Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added architecture tests (#3) #15

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
60 changes: 60 additions & 0 deletions kotlin-name-generator-archtests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.gleex.kng</groupId>
<artifactId>kotlin-name-generator-parent</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>

<artifactId>kotlin-name-generator-archtests</artifactId>

<name>Kotlin Name Generator (KNG) Architecture tests</name>
<description>Architecture unit tests to ensure specific rules</description>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</dependency>

<dependency>
<groupId>de.gleex.kng</groupId>
<artifactId>kotlin-name-generator-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>de.gleex.kng</groupId>
<artifactId>kotlin-name-generator</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>de.gleex.kng</groupId>
<artifactId>kotlin-name-generator-examples</artifactId>
<version>${project.version}</version>
</dependency>

<!-- test -->
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package de.gleex.kng.archtests

import com.tngtech.archunit.junit.AnalyzeClasses
import com.tngtech.archunit.junit.ArchTest
import com.tngtech.archunit.library.Architectures.layeredArchitecture
import com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices

@AnalyzeClasses(packages = ["de.gleex.kng"])
class GeneralPackageRules {
@ArchTest
val layersRule = layeredArchitecture().consideringOnlyDependenciesInLayers()
.layer("API").definedBy("de.gleex.kng.api..")
.layer("Generators").definedBy("de.gleex.kng.generators..")
.layer("Wordlists").definedBy("de.gleex.kng.wordlist..")
.layer("Examples").definedBy("de.gleex.kng.examples..")
.layer("Archtests").definedBy("de.gleex.kng.archtests..")
.whereLayer("Examples").mayNotBeAccessedByAnyLayer()
.whereLayer("Archtests").mayNotBeAccessedByAnyLayer()
.whereLayer("API").mayNotAccessAnyLayer()
.whereLayer("Wordlists").mayOnlyAccessLayers("API")
.whereLayer("Generators").mayOnlyAccessLayers("API", "Wordlists")

@ArchTest
val noCycles = slices().matching("de.gleex.kng.(*)..").should().beFreeOfCycles()
}
11 changes: 11 additions & 0 deletions kotlin-name-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
<version>1.4.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.oshai</groupId>
<artifactId>kotlin-logging-jvm</artifactId>
<version>5.1.1</version>
</dependency>

<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-runner-junit5-jvm</artifactId>
Expand All @@ -53,6 +59,11 @@
<artifactId>mockk-jvm</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:JvmName("NameGenerators")
package de.gleex.kng.generators

import de.gleex.kng.api.NameGenerator
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package de.gleex.kng.architecture

import com.tngtech.archunit.junit.AnalyzeClasses
import com.tngtech.archunit.junit.ArchTest
import com.tngtech.archunit.library.Architectures
import com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices

@AnalyzeClasses(packages = ["de.gleex.kng"])
class PackageRules {
@ArchTest
val layersRule = Architectures.layeredArchitecture().consideringAllDependencies()
.layer("API").definedBy("de.gleex.kng.api..")
// TODO: finish layers or use slices
.whereLayer("API").mayNotBeAccessedByAnyLayer()

@ArchTest
val noCycles = slices().matching("de.gleex.kng.(*)..").should().beFreeOfCycles()

@ArchTest
val independence = slices().matching("de.gleex.kng.(**)..")
.should().notDependOnEachOther()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.gleex.kng.architecture

import com.tngtech.archunit.core.domain.JavaMember.Predicates.declaredIn
import com.tngtech.archunit.core.importer.ImportOption
import com.tngtech.archunit.junit.AnalyzeClasses
import com.tngtech.archunit.junit.ArchTest
import com.tngtech.archunit.lang.syntax.ArchRuleDefinition.constructors
import de.gleex.kng.api.NameGenerator
import io.github.oshai.kotlinlogging.KotlinLogging

private val log = KotlinLogging.logger { }

@AnalyzeClasses(packages = ["de.gleex.kng"], importOptions = [ImportOption.DoNotIncludeTests::class])
class VisibilityTest {
@ArchTest
val constructorsOnlyInBuilder = constructors()
.that()
.areDeclaredInClassesThat().implement(NameGenerator::class.java)
.should()
.onlyBeCalled()
.byMethodsThat(declaredIn("de.gleex.kng.generators.NameGenerators"))
.orShould()
.onlyBeCalled()
.byClassesThat().implement(NameGenerator::class.java)
.orShould()
.onlyBeCalled()
.byClassesThat().haveFullyQualifiedName("de.gleex.kng.generators.ExtensionsKt")
}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<module>kotlin-name-generator-api</module>
<module>kotlin-name-generator</module>
<module>kotlin-name-generator-examples</module>
<module>kotlin-name-generator-archtests</module>
</modules>

<dependencyManagement>
Expand All @@ -58,11 +59,10 @@
<version>1.13.5</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<version>1.0.1</version>
<version>1.2.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Loading