|
1 | 1 | package com.pivovarit.collectors;
|
2 | 2 |
|
3 |
| -import com.tngtech.archunit.core.domain.JavaClasses; |
4 |
| -import com.tngtech.archunit.core.importer.ClassFileImporter; |
5 |
| -import org.junit.jupiter.api.Test; |
| 3 | +import com.tngtech.archunit.core.importer.ImportOption; |
| 4 | +import com.tngtech.archunit.junit.AnalyzeClasses; |
| 5 | +import com.tngtech.archunit.junit.ArchTest; |
| 6 | +import com.tngtech.archunit.lang.ArchRule; |
6 | 7 |
|
7 | 8 | import static com.tngtech.archunit.core.domain.JavaModifier.FINAL;
|
8 |
| -import static com.tngtech.archunit.core.importer.ImportOption.Predefined.DO_NOT_INCLUDE_ARCHIVES; |
9 |
| -import static com.tngtech.archunit.core.importer.ImportOption.Predefined.DO_NOT_INCLUDE_JARS; |
10 |
| -import static com.tngtech.archunit.core.importer.ImportOption.Predefined.DO_NOT_INCLUDE_TESTS; |
11 | 9 | import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
|
12 | 10 |
|
| 11 | +@AnalyzeClasses(packages = "com.pivovarit", importOptions = ImportOption.DoNotIncludeTests.class) |
13 | 12 | class ArchitectureTest {
|
14 | 13 |
|
15 |
| - private static final JavaClasses classes = new ClassFileImporter() |
16 |
| - .withImportOption(DO_NOT_INCLUDE_TESTS) |
17 |
| - .withImportOption(DO_NOT_INCLUDE_JARS) |
18 |
| - .withImportOption(DO_NOT_INCLUDE_ARCHIVES) |
19 |
| - .importPackages("com.pivovarit"); |
20 |
| - |
21 |
| - @Test |
22 |
| - void shouldHaveSingleFacade() { |
23 |
| - classes() |
24 |
| - .that().arePublic() |
25 |
| - .should().haveSimpleName("ParallelCollectors").orShould().haveSimpleName("Batching") |
26 |
| - .andShould().haveOnlyFinalFields() |
27 |
| - .andShould().haveOnlyPrivateConstructors() |
28 |
| - .andShould().haveModifier(FINAL) |
29 |
| - .as("all public factory methods should be accessible from the ParallelCollectors and ParallelCollectors.Batching classes") |
30 |
| - .because("users of ParallelCollectors should have a single entry point") |
31 |
| - .check(classes); |
32 |
| - } |
33 |
| - |
34 |
| - @Test |
35 |
| - void shouldHaveBatchingClassesInsideParallelCollectors() { |
36 |
| - classes() |
37 |
| - .that().arePublic().and().haveSimpleName("Batching") |
38 |
| - .should().beNestedClasses() |
39 |
| - .as("all Batching classes are sub namespaces of ParallelCollectors") |
40 |
| - .check(classes); |
41 |
| - } |
42 |
| - |
43 |
| - @Test |
44 |
| - void shouldHaveZeroDependencies() { |
45 |
| - classes() |
46 |
| - .that().resideInAPackage("com.pivovarit.collectors") |
47 |
| - .should() |
48 |
| - .onlyDependOnClassesThat() |
49 |
| - .resideInAnyPackage("com.pivovarit.collectors", "java..") |
50 |
| - .as("the library should depend only on core Java classes") |
51 |
| - .because("users appreciate not experiencing a dependency hell") |
52 |
| - .check(classes); |
53 |
| - } |
54 |
| - |
55 |
| - @Test |
56 |
| - void shouldHaveSinglePackage() { |
57 |
| - classes() |
58 |
| - .should().resideInAPackage("com.pivovarit.collectors") |
59 |
| - .check(classes); |
60 |
| - } |
61 |
| - |
62 |
| - @Test |
63 |
| - void shouldHaveTwoPublicClasses() { |
64 |
| - classes() |
65 |
| - .that().haveSimpleName("ParallelCollectors").or().haveSimpleName("Batching") |
66 |
| - .should().bePublic().andShould().haveModifier(FINAL) |
67 |
| - .check(classes); |
68 |
| - } |
| 14 | + @ArchTest |
| 15 | + static final ArchRule shouldHaveSingleFacade = classes() |
| 16 | + .that().arePublic() |
| 17 | + .should().haveSimpleName("ParallelCollectors").orShould().haveSimpleName("Batching") |
| 18 | + .andShould().haveOnlyFinalFields() |
| 19 | + .andShould().haveOnlyPrivateConstructors() |
| 20 | + .andShould().haveModifier(FINAL) |
| 21 | + .as("all public factory methods should be accessible from the ParallelCollectors and ParallelCollectors.Batching classes") |
| 22 | + .because("users of ParallelCollectors should have a single entry point"); |
| 23 | + |
| 24 | + @ArchTest |
| 25 | + static final ArchRule shouldHaveBatchingClassesInsideParallelCollectors = classes() |
| 26 | + .that().arePublic().and().haveSimpleName("Batching") |
| 27 | + .should().beNestedClasses() |
| 28 | + .as("all Batching classes are sub namespaces of ParallelCollectors"); |
| 29 | + |
| 30 | + @ArchTest |
| 31 | + static final ArchRule shouldHaveZeroDependencies = classes() |
| 32 | + .that().resideInAPackage("com.pivovarit.collectors") |
| 33 | + .should() |
| 34 | + .onlyDependOnClassesThat() |
| 35 | + .resideInAnyPackage("com.pivovarit.collectors", "java..") |
| 36 | + .as("the library should depend only on core Java classes") |
| 37 | + .because("users appreciate not experiencing a dependency hell"); |
| 38 | + |
| 39 | + @ArchTest |
| 40 | + static final ArchRule shouldHaveSinglePackage = classes() |
| 41 | + .should().resideInAPackage("com.pivovarit.collectors"); |
| 42 | + |
| 43 | + @ArchTest |
| 44 | + static final ArchRule shouldHaveTwoPublicClasses = classes() |
| 45 | + .that().haveSimpleName("ParallelCollectors").or().haveSimpleName("Batching") |
| 46 | + .should().bePublic().andShould().haveModifier(FINAL); |
69 | 47 | }
|
0 commit comments