Skip to content

Commit 059894d

Browse files
committed
improve dogfood test
1 parent fc930ee commit 059894d

File tree

9 files changed

+156
-91
lines changed

9 files changed

+156
-91
lines changed

code-assert-gui/src/test/java/guru/nidi/codeassert/gui/CodeTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import guru.nidi.codeassert.dependency.*;
2222
import guru.nidi.codeassert.findbugs.*;
2323
import guru.nidi.codeassert.junit.CodeAssertJunit5Test;
24-
import guru.nidi.codeassert.junit.PredefConfig;
2524
import guru.nidi.codeassert.pmd.*;
2625
import org.junit.jupiter.api.Test;
2726

@@ -55,7 +54,7 @@ public void defineRules() {
5554
protected FindBugsResult analyzeFindBugs() {
5655
// return null; //TODO JVM crashes, WTF!?
5756
final BugCollector bugCollector = new BugCollector()
58-
.apply(PredefConfig.minimalFindBugsIgnore())
57+
.apply(FindBugsConfigs.minimalFindBugsIgnore())
5958
// TODO fix
6059
.just(In.clazz(AppController.class).ignore("PATH_TRAVERSAL_IN"))
6160
.just(In.everywhere().ignore("SE_NO_SERIALVERSIONID", "SPRING_ENDPOINT"));
@@ -65,23 +64,23 @@ protected FindBugsResult analyzeFindBugs() {
6564
@Override
6665
protected PmdResult analyzePmd() {
6766
final PmdViolationCollector collector = new PmdViolationCollector()//.minPriority(RulePriority.MEDIUM)
68-
.apply(PredefConfig.minimalPmdIgnore());
67+
.apply(PmdConfigs.minimalPmdIgnore());
6968
return new PmdAnalyzer(AnalyzerConfig.maven().main(), collector)
70-
.withRulesets(PredefConfig.defaultPmdRulesets())
69+
.withRulesets(PmdConfigs.defaultPmdRulesets())
7170
.analyze();
7271
}
7372

7473
@Override
7574
protected CpdResult analyzeCpd() {
7675
final CpdMatchCollector collector = new CpdMatchCollector()
77-
.apply(PredefConfig.cpdIgnoreEqualsHashCodeToString());
76+
.apply(PmdConfigs.cpdIgnoreEqualsHashCodeToString());
7877
return new CpdAnalyzer(AnalyzerConfig.maven().main(), 35, collector).analyze();
7978
}
8079

8180
@Override
8281
protected CheckstyleResult analyzeCheckstyle() {
8382
final StyleEventCollector collector = new StyleEventCollector()
84-
.apply(PredefConfig.minimalCheckstyleIgnore());
85-
return new CheckstyleAnalyzer(AnalyzerConfig.maven().main(), PredefConfig.adjustedGoogleStyleChecks(), collector).analyze();
83+
.apply(CheckstyleConfigs.minimalCheckstyleIgnore());
84+
return new CheckstyleAnalyzer(AnalyzerConfig.maven().main(), CheckstyleConfigs.adjustedGoogleStyleChecks(), collector).analyze();
8685
}
8786
}

code-assert/pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45

56
<parent>
@@ -27,7 +28,7 @@
2728
<plugin>
2829
<groupId>guru.nidi</groupId>
2930
<artifactId>code-assert-maven-plugin</artifactId>
30-
<version>0.9.4</version>
31+
<version>0.9.5</version>
3132
<executions>
3233
<execution>
3334
<goals>
@@ -85,6 +86,11 @@
8586
</build>
8687

8788
<dependencies>
89+
<dependency>
90+
<groupId>guru.nidi</groupId>
91+
<artifactId>graphviz-java</artifactId>
92+
<version>0.8.2</version>
93+
</dependency>
8894
<dependency>
8995
<groupId>org.hamcrest</groupId>
9096
<artifactId>hamcrest-core</artifactId>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright © 2015 Stefan Niederhauser ([email protected])
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package guru.nidi.codeassert.checkstyle;
17+
18+
import guru.nidi.codeassert.config.*;
19+
20+
import static com.puppycrawl.tools.checkstyle.api.TokenTypes.*;
21+
22+
public final class CheckstyleConfigs {
23+
private static final String VARIABLE_PATTERN = "^[a-z][a-zA-Z0-9]*$";
24+
25+
private CheckstyleConfigs() {
26+
}
27+
28+
public static StyleChecks.Google adjustedGoogleStyleChecks() {
29+
return StyleChecks.google()
30+
.maxLineLen(120).indentBasic(4).indentCase(4)
31+
.paramName(VARIABLE_PATTERN)
32+
.catchParamName(VARIABLE_PATTERN)
33+
.localVarName(VARIABLE_PATTERN)
34+
.memberName(VARIABLE_PATTERN)
35+
.methodName(VARIABLE_PATTERN)
36+
.emptyLineSeparatorTokens(IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
37+
STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF);
38+
}
39+
40+
public static CollectorTemplate<Ignore> minimalCheckstyleIgnore() {
41+
return CollectorTemplate.of(Ignore.class)
42+
.because("I don't agree", In.everywhere()
43+
.ignore("import.avoidStar", "custom.import.order.nonGroup.expected", "custom.import.order.lex",
44+
"javadoc.packageInfo", "javadoc.missing",
45+
"multiple.variable.declarations.comma", "final.parameter",
46+
"design.forExtension", "hidden.field", "inline.conditional.avoid", "magic.number"));
47+
}
48+
49+
public static StyleChecks.Sun adjustedSunStyleChecks() {
50+
return StyleChecks.sun().maxLineLen(120).allowDefaultAccessMembers(true);
51+
}
52+
53+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright © 2015 Stefan Niederhauser ([email protected])
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package guru.nidi.codeassert.findbugs;
17+
18+
import guru.nidi.codeassert.config.*;
19+
20+
import static guru.nidi.codeassert.config.Language.KOTLIN;
21+
22+
public final class FindBugsConfigs {
23+
private FindBugsConfigs() {
24+
}
25+
26+
public static CollectorTemplate<Ignore> minimalFindBugsIgnore() {
27+
return CollectorTemplate.forA(BugCollector.class)
28+
.because("modern compilers are clever", In.everywhere().ignore(
29+
"SBSC_USE_STRINGBUFFER_CONCATENATION"))
30+
.because("it's compiler generated code", In.languages(KOTLIN).ignore(
31+
"ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", "BC_BAD_CAST_TO_ABSTRACT_COLLECTION"))
32+
.because("it's compiler generated code, but why?", In.languages(KOTLIN).ignore(
33+
"NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE"))
34+
.because("findbugs seems to be cleverer than kotlin compiler", In.languages(KOTLIN).ignore(
35+
"RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE"))
36+
.because("inline methods seem to cause this", In.languages(KOTLIN).ignore(
37+
"UPM_UNCALLED_PRIVATE_METHOD"));
38+
}
39+
40+
public static CollectorTemplate<Ignore> dependencyTestIgnore(Class<?> dependencyTest) {
41+
return CollectorTemplate.of(Ignore.class).just(In.clazz(dependencyTest)
42+
.ignore("NP_UNWRITTEN_FIELD", "UWF_UNWRITTEN_FIELD", "UUF_UNUSED_FIELD"));
43+
}
44+
45+
}

code-assert/src/main/java/guru/nidi/codeassert/junit/CodeAssertJunit5Test.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,71 +28,71 @@
2828
public class CodeAssertJunit5Test extends CodeAssertTestBase {
2929
@Test
3030
void dependencies() {
31-
assumeFalse(dependencyResult() == null, "analyzeDependencies() not implemented.");
3231
assumeTrue(defaultTests().contains(DEPENDENCIES), "Dependencies test excluded.");
32+
assumeFalse(dependencyResult() == null, "analyzeDependencies() not implemented.");
3333
assertThat(dependencyResult(), matchesRulesExactly());
3434
}
3535

3636
@Test
3737
void circularDependencies() {
38-
assumeFalse(dependencyResult() == null, "analyzeDependencies() not implemented.");
3938
assumeTrue(defaultTests().contains(CIRCULAR_DEPENDENCIES), "Circular dependencies test excluded.");
39+
assumeFalse(dependencyResult() == null, "analyzeDependencies() not implemented.");
4040
assertThat(dependencyResult(), hasNoCycles());
4141
}
4242

4343
@Test
4444
void findBugs() {
45-
assumeFalse(findBugsResult() == null, "analyzeFindBugs() not implemented.");
4645
assumeTrue(defaultTests().contains(FIND_BUGS), "FindBugs test excluded.");
46+
assumeFalse(findBugsResult() == null, "analyzeFindBugs() not implemented.");
4747
assertThat(findBugsResult(), hasNoBugs());
4848
}
4949

5050
@Test
5151
void findBugsUnusedActions() {
52-
assumeFalse(findBugsResult() == null, "analyzeFindBugs() not implemented.");
5352
assumeTrue(defaultTests().contains(FIND_BUGS_UNUSED_ACTIONS), "FindBugs - unused actions test excluded.");
53+
assumeFalse(findBugsResult() == null, "analyzeFindBugs() not implemented.");
5454
assertThat(findBugsResult(), hasNoUnusedActions());
5555
}
5656

5757
@Test
5858
void pmdViolations() {
59-
assumeFalse(pmdResult() == null, "analyzePmd() not implemented.");
6059
assumeTrue(defaultTests().contains(PMD), "PMD test excluded.");
60+
assumeFalse(pmdResult() == null, "analyzePmd() not implemented.");
6161
assertThat(pmdResult(), hasNoPmdViolations());
6262
}
6363

6464
@Test
6565
void pmdUnusedActions() {
66-
assumeFalse(pmdResult() == null, "analyzePmd() not implemented.");
6766
assumeTrue(defaultTests().contains(PMD_UNUSED_ACTIONS), "PMD - unused actions test excluded.");
67+
assumeFalse(pmdResult() == null, "analyzePmd() not implemented.");
6868
assertThat(pmdResult(), hasNoUnusedActions());
6969
}
7070

7171
@Test
7272
void cpd() {
73-
assumeFalse(cpdResult() == null, "analyzeCpd() not implemented.");
7473
assumeTrue(defaultTests().contains(CPD), "CPD test excluded.");
74+
assumeFalse(cpdResult() == null, "analyzeCpd() not implemented.");
7575
assertThat(cpdResult(), hasNoCodeDuplications());
7676
}
7777

7878
@Test
7979
void cpdUnusedActions() {
80-
assumeFalse(cpdResult() == null, "analyzeCpd() not implemented.");
8180
assumeTrue(defaultTests().contains(CPD_UNUSED_ACTIONS), "CPD - unused actions test excluded.");
81+
assumeFalse(cpdResult() == null, "analyzeCpd() not implemented.");
8282
assertThat(cpdResult(), hasNoUnusedActions());
8383
}
8484

8585
@Test
8686
void checkstyle() {
87-
assumeFalse(checkstyleResult() == null, "analyzeCheckstyle() not implemented.");
8887
assumeTrue(defaultTests().contains(CHECKSTYLE), "Checkstyle test excluded.");
88+
assumeFalse(checkstyleResult() == null, "analyzeCheckstyle() not implemented.");
8989
assertThat(checkstyleResult(), hasNoCheckstyleIssues());
9090
}
9191

9292
@Test
9393
void checkstyleUnusedActions() {
94-
assumeFalse(checkstyleResult() == null, "analyzeCheckstyle() not implemented.");
9594
assumeTrue(defaultTests().contains(CHECKSTYLE_UNUSED_ACTIONS), "Checkstyle - unused actions test excluded.");
95+
assumeFalse(checkstyleResult() == null, "analyzeCheckstyle() not implemented.");
9696
assertThat(checkstyleResult(), hasNoUnusedActions());
9797
}
9898

code-assert/src/main/java/guru/nidi/codeassert/junit/CodeAssertTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,71 +28,71 @@
2828
public class CodeAssertTest extends CodeAssertTestBase {
2929
@Test
3030
public void dependencies() {
31-
assumeFalse("analyzeDependencies() not implemented.", dependencyResult() == null);
3231
assumeTrue("Dependencies test excluded.", defaultTests().contains(DEPENDENCIES));
32+
assumeFalse("analyzeDependencies() not implemented.", dependencyResult() == null);
3333
assertThat(dependencyResult(), matchesRulesExactly());
3434
}
3535

3636
@Test
3737
public void circularDependencies() {
38-
assumeFalse("analyzeDependencies() not implemented.", dependencyResult() == null);
3938
assumeTrue("Circular dependencies test excluded.", defaultTests().contains(CIRCULAR_DEPENDENCIES));
39+
assumeFalse("analyzeDependencies() not implemented.", dependencyResult() == null);
4040
assertThat(dependencyResult(), hasNoCycles());
4141
}
4242

4343
@Test
4444
public void findBugs() {
45-
assumeFalse("analyzeFindBugs() not implemented.", findBugsResult() == null);
4645
assumeTrue("FindBugs test excluded.", defaultTests().contains(FIND_BUGS));
46+
assumeFalse("analyzeFindBugs() not implemented.", findBugsResult() == null);
4747
assertThat(findBugsResult(), hasNoBugs());
4848
}
4949

5050
@Test
5151
public void findBugsUnusedActions() {
52-
assumeFalse("analyzeFindBugs() not implemented.", findBugsResult() == null);
5352
assumeTrue("FindBugs - unused actions test excluded.", defaultTests().contains(FIND_BUGS_UNUSED_ACTIONS));
53+
assumeFalse("analyzeFindBugs() not implemented.", findBugsResult() == null);
5454
assertThat(findBugsResult(), hasNoUnusedActions());
5555
}
5656

5757
@Test
5858
public void pmdViolations() {
59-
assumeFalse("analyzePmd() not implemented.", pmdResult() == null);
6059
assumeTrue("PMD test excluded.", defaultTests().contains(PMD));
60+
assumeFalse("analyzePmd() not implemented.", pmdResult() == null);
6161
assertThat(pmdResult(), hasNoPmdViolations());
6262
}
6363

6464
@Test
6565
public void pmdUnusedActions() {
66-
assumeFalse("analyzePmd() not implemented.", pmdResult() == null);
6766
assumeTrue("PMD - unused actions test excluded.", defaultTests().contains(PMD_UNUSED_ACTIONS));
67+
assumeFalse("analyzePmd() not implemented.", pmdResult() == null);
6868
assertThat(pmdResult(), hasNoUnusedActions());
6969
}
7070

7171
@Test
7272
public void cpd() {
73-
assumeFalse("analyzeCpd() not implemented.", cpdResult() == null);
7473
assumeTrue("CPD test excluded.", defaultTests().contains(CPD));
74+
assumeFalse("analyzeCpd() not implemented.", cpdResult() == null);
7575
assertThat(cpdResult(), hasNoCodeDuplications());
7676
}
7777

7878
@Test
7979
public void cpdUnusedActions() {
80-
assumeFalse("analyzeCpd() not implemented.", cpdResult() == null);
8180
assumeTrue("CPD - unused actions test excluded.", defaultTests().contains(CPD_UNUSED_ACTIONS));
81+
assumeFalse("analyzeCpd() not implemented.", cpdResult() == null);
8282
assertThat(cpdResult(), hasNoUnusedActions());
8383
}
8484

8585
@Test
8686
public void checkstyle() {
87-
assumeFalse("analyzeCheckstyle() not implemented.", checkstyleResult() == null);
8887
assumeTrue("Checkstyle test excluded.", defaultTests().contains(CHECKSTYLE));
88+
assumeFalse("analyzeCheckstyle() not implemented.", checkstyleResult() == null);
8989
assertThat(checkstyleResult(), hasNoCheckstyleIssues());
9090
}
9191

9292
@Test
9393
public void checkstyleUnusedActions() {
94-
assumeFalse("analyzeCheckstyle() not implemented.", checkstyleResult() == null);
9594
assumeTrue("Checkstyle - unused actions test excluded.", defaultTests().contains(CHECKSTYLE_UNUSED_ACTIONS));
95+
assumeFalse("analyzeCheckstyle() not implemented.", checkstyleResult() == null);
9696
assertThat(checkstyleResult(), hasNoUnusedActions());
9797
}
9898

0 commit comments

Comments
 (0)