|
1 | 1 | package com.pivovarit.function; |
2 | 2 |
|
3 | | -import com.tngtech.archunit.core.domain.JavaClasses; |
4 | | -import com.tngtech.archunit.core.importer.ClassFileImporter; |
| 3 | +import com.tngtech.archunit.core.importer.ImportOption; |
| 4 | +import com.tngtech.archunit.junit.AnalyzeClasses; |
| 5 | +import com.tngtech.archunit.junit.ArchTest; |
5 | 6 | import com.tngtech.archunit.lang.ArchRule; |
6 | | -import org.junit.jupiter.api.Test; |
7 | 7 |
|
8 | 8 | import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; |
9 | 9 |
|
| 10 | +@AnalyzeClasses(packages = "com.pivovarit", importOptions = ImportOption.DoNotIncludeTests.class) |
10 | 11 | class ArchitectureTest { |
11 | 12 |
|
12 | | - private static final ArchRule SINGLE_PACKAGE_RULE = classes() |
13 | | - .should().resideInAPackage("com.pivovarit.function"); |
| 13 | + private static final String COM_PIVOVARIT_FUNCTION = "com.pivovarit.function"; |
14 | 14 |
|
15 | | - private static final ArchRule PUBLIC_INTERFACES = classes() |
| 15 | + @ArchTest |
| 16 | + static final ArchRule shouldHaveSinglePackage = classes() |
| 17 | + .should().resideInAPackage(COM_PIVOVARIT_FUNCTION); |
| 18 | + |
| 19 | + @ArchTest |
| 20 | + static final ArchRule shouldHaveOnlyPublicInterfaces = classes() |
16 | 21 | .that().arePublic().and().areInterfaces() |
17 | 22 | .should().beInterfaces() |
18 | 23 | .andShould().haveSimpleNameStartingWith("Throwing"); |
19 | 24 |
|
20 | | - private static final ArchRule ZERO_DEPS_RULE = classes() |
21 | | - .that().resideInAPackage("com.pivovarit.function") |
| 25 | + @ArchTest |
| 26 | + static final ArchRule shouldHaveZeroDependencies = classes() |
| 27 | + .that().resideInAPackage(COM_PIVOVARIT_FUNCTION) |
22 | 28 | .should() |
23 | 29 | .dependOnClassesThat().resideInAPackage("java..") |
24 | 30 | .as("the library should depend only on core Java classes") |
25 | 31 | .because("users appreciate not experiencing a dependency hell"); |
26 | | - |
27 | | - private static final JavaClasses classes = new ClassFileImporter() |
28 | | - .importPackages("com.pivovarit"); |
29 | | - |
30 | | - @Test |
31 | | - void shouldHavePublicInterfacesWithCorrectNamingPattern() { |
32 | | - PUBLIC_INTERFACES.check(classes); |
33 | | - } |
34 | | - |
35 | | - @Test |
36 | | - void shouldHaveZeroDependencies() { |
37 | | - ZERO_DEPS_RULE.check(classes); |
38 | | - } |
39 | | - |
40 | | - @Test |
41 | | - void shouldHaveSinglePackage() { |
42 | | - SINGLE_PACKAGE_RULE.check(classes); |
43 | | - } |
44 | 32 | } |
0 commit comments