Skip to content

Commit bc89191

Browse files
authored
Refactor ArchUnit tests (#224)
1 parent a6ed529 commit bc89191

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed
Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,32 @@
11
package com.pivovarit.function;
22

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;
56
import com.tngtech.archunit.lang.ArchRule;
6-
import org.junit.jupiter.api.Test;
77

88
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
99

10+
@AnalyzeClasses(packages = "com.pivovarit", importOptions = ImportOption.DoNotIncludeTests.class)
1011
class ArchitectureTest {
1112

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";
1414

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()
1621
.that().arePublic().and().areInterfaces()
1722
.should().beInterfaces()
1823
.andShould().haveSimpleNameStartingWith("Throwing");
1924

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)
2228
.should()
2329
.dependOnClassesThat().resideInAPackage("java..")
2430
.as("the library should depend only on core Java classes")
2531
.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-
}
4432
}

0 commit comments

Comments
 (0)