This commit is contained in:
@@ -145,6 +145,35 @@ class StandardsTest {
|
||||
assertFalse(findings.stream().anyMatch(s -> s.contains("requires final: count")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void patternBindingsRequireFinalOnlyWhenAssignedOnce() throws Exception {
|
||||
var findings = analyze("""
|
||||
record Pair(Object key, Object value) {}
|
||||
class Fixture {
|
||||
public void run(final Object input) {
|
||||
if (input instanceof String unchanged) { System.out.println(unchanged); }
|
||||
if (input instanceof final String protectedValue) { System.out.println(protectedValue); }
|
||||
if (input instanceof String reassigned) { reassigned = reassigned.trim(); System.out.println(reassigned); }
|
||||
switch (input) {
|
||||
case String switched -> System.out.println(switched);
|
||||
default -> {}
|
||||
}
|
||||
if (input instanceof Pair(var key, var value)) {
|
||||
System.out.println(key);
|
||||
System.out.println(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
""");
|
||||
for (String binding : List.of("unchanged", "switched", "key", "value"))
|
||||
assertTrue(findings.stream().anyMatch(s -> s.contains("requires final: " + binding)),
|
||||
findings.toString());
|
||||
for (String binding : List.of("protectedValue", "reassigned"))
|
||||
assertFalse(findings.stream().anyMatch(s -> s.contains("requires final: " + binding)),
|
||||
findings.toString());
|
||||
assertFalse(findings.stream().anyMatch(s -> s.contains("var requires")), findings.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void inheritanceCountsOnlyProjectSuperclasses() throws Exception {
|
||||
var findings = analyze(
|
||||
@@ -202,6 +231,30 @@ class StandardsTest {
|
||||
assertTrue(contains(findings, "METRIC", "publicMethods=3.0"), findings.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void commentedAccessorsRemainTrivialWhileAdditionalWorkStillCounts() throws Exception {
|
||||
var findings = analyze("""
|
||||
class Fixture {
|
||||
private String name;
|
||||
private String trimmed;
|
||||
private String logged;
|
||||
private String calculated;
|
||||
private String appended;
|
||||
public String getName() { /* Intent comment. */ return name; }
|
||||
public void setName(final String value) { this./* Field comment. */name = value; }
|
||||
public String name() { // Read the stored value.
|
||||
return this.name;
|
||||
}
|
||||
public void setName(final String value, final boolean validate) { this.name = value; }
|
||||
public void setTrimmed(final String value) { this.trimmed = value.trim(); }
|
||||
public String getLogged() { System.out.println(logged); return logged; }
|
||||
public String getCalculated() { return calculated.trim(); }
|
||||
public void setAppended(final String value) { this.appended += value; }
|
||||
}
|
||||
""");
|
||||
assertTrue(contains(findings, "METRIC", "publicMethods=5.0"), findings.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void classLengthBoundaryAndNestedTypeLines() throws Exception {
|
||||
assertTrue(contains(
|
||||
|
||||
Reference in New Issue
Block a user