-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
60 deletions.
There are no files selected for viewing
97 changes: 37 additions & 60 deletions
97
src/test/java/com/pivovarit/collectors/ArchitectureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,46 @@ | ||
package com.pivovarit.collectors; | ||
|
||
import com.tngtech.archunit.core.domain.JavaClasses; | ||
import com.tngtech.archunit.core.importer.ClassFileImporter; | ||
import org.junit.jupiter.api.Test; | ||
import com.tngtech.archunit.junit.AnalyzeClasses; | ||
import com.tngtech.archunit.junit.ArchTest; | ||
import com.tngtech.archunit.lang.ArchRule; | ||
|
||
import static com.tngtech.archunit.core.domain.JavaModifier.FINAL; | ||
import static com.tngtech.archunit.core.importer.ImportOption.Predefined.DO_NOT_INCLUDE_ARCHIVES; | ||
import static com.tngtech.archunit.core.importer.ImportOption.Predefined.DO_NOT_INCLUDE_JARS; | ||
import static com.tngtech.archunit.core.importer.ImportOption.Predefined.DO_NOT_INCLUDE_TESTS; | ||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; | ||
|
||
@AnalyzeClasses(packages = "com.pivovarit") | ||
class ArchitectureTest { | ||
|
||
private static final JavaClasses classes = new ClassFileImporter() | ||
.withImportOption(DO_NOT_INCLUDE_TESTS) | ||
.withImportOption(DO_NOT_INCLUDE_JARS) | ||
.withImportOption(DO_NOT_INCLUDE_ARCHIVES) | ||
.importPackages("com.pivovarit"); | ||
|
||
@Test | ||
void shouldHaveSingleFacade() { | ||
classes() | ||
.that().arePublic() | ||
.should().haveSimpleName("ParallelCollectors").orShould().haveSimpleName("Batching") | ||
.andShould().haveOnlyFinalFields() | ||
.andShould().haveOnlyPrivateConstructors() | ||
.andShould().haveModifier(FINAL) | ||
.as("all public factory methods should be accessible from the ParallelCollectors and ParallelCollectors.Batching classes") | ||
.because("users of ParallelCollectors should have a single entry point") | ||
.check(classes); | ||
} | ||
|
||
@Test | ||
void shouldHaveBatchingClassesInsideParallelCollectors() { | ||
classes() | ||
.that().arePublic().and().haveSimpleName("Batching") | ||
.should().beNestedClasses() | ||
.as("all Batching classes are sub namespaces of ParallelCollectors") | ||
.check(classes); | ||
} | ||
|
||
@Test | ||
void shouldHaveZeroDependencies() { | ||
classes() | ||
.that().resideInAPackage("com.pivovarit.collectors") | ||
.should() | ||
.onlyDependOnClassesThat() | ||
.resideInAnyPackage("com.pivovarit.collectors", "java..") | ||
.as("the library should depend only on core Java classes") | ||
.because("users appreciate not experiencing a dependency hell") | ||
.check(classes); | ||
} | ||
|
||
@Test | ||
void shouldHaveSinglePackage() { | ||
classes() | ||
.should().resideInAPackage("com.pivovarit.collectors") | ||
.check(classes); | ||
} | ||
|
||
@Test | ||
void shouldHaveTwoPublicClasses() { | ||
classes() | ||
.that().haveSimpleName("ParallelCollectors").or().haveSimpleName("Batching") | ||
.should().bePublic().andShould().haveModifier(FINAL) | ||
.check(classes); | ||
} | ||
@ArchTest | ||
static final ArchRule shouldHaveSingleFacade = classes() | ||
.that().arePublic() | ||
.should().haveSimpleName("ParallelCollectors").orShould().haveSimpleName("Batching") | ||
.andShould().haveOnlyFinalFields() | ||
.andShould().haveOnlyPrivateConstructors() | ||
.andShould().haveModifier(FINAL) | ||
.as("all public factory methods should be accessible from the ParallelCollectors and ParallelCollectors.Batching classes") | ||
.because("users of ParallelCollectors should have a single entry point"); | ||
|
||
@ArchTest | ||
static final ArchRule shouldHaveBatchingClassesInsideParallelCollectors = classes() | ||
.that().arePublic().and().haveSimpleName("Batching") | ||
.should().beNestedClasses() | ||
.as("all Batching classes are sub namespaces of ParallelCollectors"); | ||
|
||
@ArchTest | ||
static final ArchRule shouldHaveZeroDependencies = classes() | ||
.that().resideInAPackage("com.pivovarit.collectors") | ||
.should() | ||
.onlyDependOnClassesThat() | ||
.resideInAnyPackage("com.pivovarit.collectors", "java..") | ||
.as("the library should depend only on core Java classes") | ||
.because("users appreciate not experiencing a dependency hell"); | ||
|
||
@ArchTest | ||
static final ArchRule shouldHaveSinglePackage = classes() | ||
.should().resideInAPackage("com.pivovarit.collectors"); | ||
|
||
@ArchTest | ||
static final ArchRule shouldHaveTwoPublicClasses = classes() | ||
.that().haveSimpleName("ParallelCollectors").or().haveSimpleName("Batching") | ||
.should().bePublic().andShould().haveModifier(FINAL); | ||
} |