Skip to content

Commit 7505456

Browse files
committed
split off core module
1 parent 4a17102 commit 7505456

File tree

151 files changed

+675
-182
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+675
-182
lines changed

code-assert-core/pom.xml

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<?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">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>guru.nidi</groupId>
7+
<artifactId>code-assert-parent</artifactId>
8+
<version>0.9.12-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>code-assert-core</artifactId>
12+
<name>${project.artifactId}</name>
13+
14+
<properties>
15+
<maven-jar.version>3.2.0</maven-jar.version>
16+
</properties>
17+
18+
<build>
19+
<plugins>
20+
<plugin>
21+
<groupId>guru.nidi</groupId>
22+
<artifactId>code-assert-maven-plugin</artifactId>
23+
<version>0.9.6</version>
24+
<executions>
25+
<execution>
26+
<goals>
27+
<goal>prepare</goal>
28+
<goal>assert</goal>
29+
</goals>
30+
</execution>
31+
</executions>
32+
</plugin>
33+
34+
<plugin>
35+
<groupId>guru.nidi.maven.plugins</groupId>
36+
<artifactId>snippets-maven-plugin</artifactId>
37+
<executions>
38+
<execution>
39+
<phase>generate-resources</phase>
40+
<goals>
41+
<goal>snippets</goal>
42+
</goals>
43+
<configuration>
44+
<inputs>
45+
<input>
46+
src/test/java/guru/nidi/codeassert/snippets
47+
</input>
48+
</inputs>
49+
<outputs>
50+
<output>../README.md</output>
51+
</outputs>
52+
<prefix>\n```java</prefix>
53+
<postfix>```\n</postfix>
54+
</configuration>
55+
</execution>
56+
</executions>
57+
</plugin>
58+
<plugin>
59+
<groupId>org.jetbrains.kotlin</groupId>
60+
<artifactId>kotlin-maven-plugin</artifactId>
61+
<version>${kotlin.version}</version>
62+
<executions>
63+
<execution>
64+
<id>test-compile</id>
65+
<goals>
66+
<goal>test-compile</goal>
67+
</goals>
68+
<configuration>
69+
<sourceDirs>
70+
<sourceDir>src/test/kotlin</sourceDir>
71+
</sourceDirs>
72+
</configuration>
73+
</execution>
74+
</executions>
75+
</plugin>
76+
<plugin>
77+
<groupId>org.apache.maven.plugins</groupId>
78+
<artifactId>maven-jar-plugin</artifactId>
79+
<version>${maven-jar.version}</version>
80+
<configuration>
81+
<archive>
82+
<manifestEntries>
83+
<Automatic-Module-Name>guru.nidi.codeassert</Automatic-Module-Name>
84+
</manifestEntries>
85+
</archive>
86+
</configuration>
87+
</plugin>
88+
</plugins>
89+
</build>
90+
91+
<dependencies>
92+
<dependency>
93+
<groupId>guru.nidi</groupId>
94+
<artifactId>graphviz-java</artifactId>
95+
<version>0.17.0</version>
96+
<optional>true</optional>
97+
</dependency>
98+
<dependency>
99+
<groupId>org.hamcrest</groupId>
100+
<artifactId>hamcrest-core</artifactId>
101+
<version>1.3</version>
102+
</dependency>
103+
<dependency>
104+
<groupId>commons-io</groupId>
105+
<artifactId>commons-io</artifactId>
106+
<version>2.7</version>
107+
</dependency>
108+
109+
<dependency>
110+
<groupId>junit</groupId>
111+
<artifactId>junit</artifactId>
112+
<version>4.12</version>
113+
<scope>provided</scope>
114+
</dependency>
115+
<dependency>
116+
<groupId>org.junit.jupiter</groupId>
117+
<artifactId>junit-jupiter-api</artifactId>
118+
<scope>provided</scope>
119+
</dependency>
120+
121+
<dependency>
122+
<groupId>org.slf4j</groupId>
123+
<artifactId>slf4j-api</artifactId>
124+
</dependency>
125+
<dependency>
126+
<groupId>org.slf4j</groupId>
127+
<artifactId>jcl-over-slf4j</artifactId>
128+
</dependency>
129+
<dependency>
130+
<groupId>org.slf4j</groupId>
131+
<artifactId>jul-to-slf4j</artifactId>
132+
</dependency>
133+
134+
<dependency>
135+
<groupId>org.slf4j</groupId>
136+
<artifactId>slf4j-simple</artifactId>
137+
<scope>test</scope>
138+
</dependency>
139+
</dependencies>
140+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.junit;
17+
18+
import org.junit.jupiter.api.Disabled;
19+
import org.junit.jupiter.api.Test;
20+
21+
import static guru.nidi.codeassert.junit.CodeAssertCoreMatchers.*;
22+
import static guru.nidi.codeassert.junit.CodeAssertTestType.*;
23+
import static org.hamcrest.MatcherAssert.assertThat;
24+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
25+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
26+
27+
@Disabled("This is made to be subclassed")
28+
public class CodeAssertCoreJunit5Test extends CodeAssertCoreTestBase {
29+
@Test
30+
void dependencies() {
31+
assumeTrue(defaultTests().contains(DEPENDENCIES), "Dependencies test excluded.");
32+
assumeFalse(dependencyResult() == null, "analyzeDependencies() not implemented.");
33+
assertThat(dependencyResult(), matchesRulesExactly());
34+
}
35+
36+
@Test
37+
void circularDependencies() {
38+
assumeTrue(defaultTests().contains(CIRCULAR_DEPENDENCIES), "Circular dependencies test excluded.");
39+
assumeFalse(dependencyResult() == null, "analyzeDependencies() not implemented.");
40+
assertThat(dependencyResult(), hasNoCycles());
41+
}
42+
43+
@Test
44+
void codeStructure() {
45+
assumeTrue(defaultTests().contains(STRUCTURE), "Structure tests excluded.");
46+
assumeFalse(createModel() == null, "createModel() not implemented.");
47+
assertThat(createModel(), exposesNoInternalTypes());
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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.junit;
17+
18+
import guru.nidi.codeassert.AnalyzerResult;
19+
import guru.nidi.codeassert.dependency.*;
20+
import guru.nidi.codeassert.jacoco.CoverageMatcher;
21+
import guru.nidi.codeassert.jacoco.JacocoResult;
22+
import guru.nidi.codeassert.model.*;
23+
import org.hamcrest.Matcher;
24+
25+
public final class CodeAssertCoreMatchers {
26+
private CodeAssertCoreMatchers() {
27+
}
28+
29+
public static Matcher<DependencyResult> matchesRules() {
30+
return new DependencyResultMatcher(false, false);
31+
}
32+
33+
public static Matcher<DependencyResult> matchesRulesExactly() {
34+
return new DependencyResultMatcher(true, true);
35+
}
36+
37+
public static Matcher<DependencyResult> matchesRulesIgnoringNonExisting() {
38+
return new DependencyResultMatcher(false, true);
39+
}
40+
41+
public static Matcher<DependencyResult> matchesRulesIgnoringUndefined() {
42+
return new DependencyResultMatcher(true, false);
43+
}
44+
45+
public static Matcher<Model> exposesNoInternalTypes() {
46+
return new InternalTypeInPublicApiMatcher();
47+
}
48+
49+
public static Matcher<Model> hasNoPublicMembersInInternalTypes() {
50+
return new PublicMemberInInternalTypeMatcher();
51+
}
52+
53+
public static Matcher<DependencyResult> hasNoCycles() {
54+
return new DependencyCycleMatcher();
55+
}
56+
57+
public static <T extends AnalyzerResult<?>> Matcher<T> hasNoUnusedActions() {
58+
return new UnusedActionsMatcher<>();
59+
}
60+
61+
public static Matcher<JacocoResult> hasEnoughCoverage() {
62+
return new CoverageMatcher();
63+
}
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.junit;
17+
18+
import org.junit.Ignore;
19+
import org.junit.Test;
20+
21+
import static guru.nidi.codeassert.junit.CodeAssertCoreMatchers.*;
22+
import static guru.nidi.codeassert.junit.CodeAssertTestType.*;
23+
import static org.hamcrest.MatcherAssert.assertThat;
24+
import static org.junit.Assume.assumeFalse;
25+
import static org.junit.Assume.assumeTrue;
26+
27+
@Ignore("This is made to be subclassed")
28+
public class CodeAssertCoreTest extends CodeAssertCoreTestBase {
29+
@Test
30+
public void dependencies() {
31+
assumeTrue("Dependencies test excluded.", defaultTests().contains(DEPENDENCIES));
32+
assumeFalse("analyzeDependencies() not implemented.", dependencyResult() == null);
33+
assertThat(dependencyResult(), matchesRulesExactly());
34+
}
35+
36+
@Test
37+
public void circularDependencies() {
38+
assumeTrue("Circular dependencies test excluded.", defaultTests().contains(CIRCULAR_DEPENDENCIES));
39+
assumeFalse("analyzeDependencies() not implemented.", dependencyResult() == null);
40+
assertThat(dependencyResult(), hasNoCycles());
41+
}
42+
43+
@Test
44+
public void codeStructure() {
45+
assumeTrue("Structure tests excluded.", defaultTests().contains(STRUCTURE));
46+
assumeFalse("createModel() not implemented.", createModel() == null);
47+
assertThat(createModel(), exposesNoInternalTypes());
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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.junit;
17+
18+
import guru.nidi.codeassert.dependency.DependencyResult;
19+
import guru.nidi.codeassert.model.Model;
20+
21+
import java.util.EnumSet;
22+
23+
public class CodeAssertCoreTestBase {
24+
private Model model;
25+
private DependencyResult dependencyResult;
26+
27+
protected EnumSet<CodeAssertTestType> defaultTests() {
28+
return EnumSet.allOf(CodeAssertTestType.class);
29+
}
30+
31+
protected Model createModel() {
32+
return null;
33+
}
34+
35+
protected DependencyResult analyzeDependencies() {
36+
return null;
37+
}
38+
39+
protected synchronized Model model() {
40+
if (model == null) {
41+
model = createModel();
42+
}
43+
return model;
44+
}
45+
46+
protected synchronized DependencyResult dependencyResult() {
47+
if (dependencyResult == null) {
48+
dependencyResult = analyzeDependencies();
49+
}
50+
return dependencyResult;
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import guru.nidi.codeassert.config.For;
2+
import guru.nidi.codeassert.jacoco.CoverageCollector;
3+
import guru.nidi.codeassert.jacoco.JacocoAnalyzer;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static guru.nidi.codeassert.jacoco.CoverageType.*;
7+
import static guru.nidi.codeassert.junit.CodeAssertCoreMatchers.hasEnoughCoverage;
8+
import static org.hamcrest.MatcherAssert.assertThat;
9+
10+
public class CodeCoverage {
11+
@Test
12+
void coverage() {
13+
JacocoAnalyzer analyzer = new JacocoAnalyzer(new CoverageCollector(BRANCH, LINE, METHOD)
14+
.just(For.global().setMinima(80, 80, 80))
15+
.just(For.allPackages().setMinima(75, 80, 80))
16+
.just(For.thePackage("*junit").setMinima(70, 70, 60))
17+
);
18+
assertThat(analyzer.analyze(), hasEnoughCoverage());
19+
}
20+
}

0 commit comments

Comments
 (0)