Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 14 additions & 26 deletions src/test/java/com/pivovarit/function/ArchitectureTest.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,32 @@
package com.pivovarit.function;

import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.core.importer.ImportOption;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
import org.junit.jupiter.api.Test;

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

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

private static final ArchRule SINGLE_PACKAGE_RULE = classes()
.should().resideInAPackage("com.pivovarit.function");
private static final String COM_PIVOVARIT_FUNCTION = "com.pivovarit.function";

private static final ArchRule PUBLIC_INTERFACES = classes()
@ArchTest
static final ArchRule shouldHaveSinglePackage = classes()
.should().resideInAPackage(COM_PIVOVARIT_FUNCTION);

@ArchTest
static final ArchRule shouldHaveOnlyPublicInterfaces = classes()
.that().arePublic().and().areInterfaces()
.should().beInterfaces()
.andShould().haveSimpleNameStartingWith("Throwing");

private static final ArchRule ZERO_DEPS_RULE = classes()
.that().resideInAPackage("com.pivovarit.function")
@ArchTest
static final ArchRule shouldHaveZeroDependencies = classes()
.that().resideInAPackage(COM_PIVOVARIT_FUNCTION)
.should()
.dependOnClassesThat().resideInAPackage("java..")
.as("the library should depend only on core Java classes")
.because("users appreciate not experiencing a dependency hell");

private static final JavaClasses classes = new ClassFileImporter()
.importPackages("com.pivovarit");

@Test
void shouldHavePublicInterfacesWithCorrectNamingPattern() {
PUBLIC_INTERFACES.check(classes);
}

@Test
void shouldHaveZeroDependencies() {
ZERO_DEPS_RULE.check(classes);
}

@Test
void shouldHaveSinglePackage() {
SINGLE_PACKAGE_RULE.check(classes);
}
}