-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathOnionArchitectureTest.kt
64 lines (54 loc) · 2.41 KB
/
OnionArchitectureTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.github.spanierm.archunitjunit5kotlin.onion
import com.tngtech.archunit.junit.AnalyzeClasses
import com.tngtech.archunit.junit.ArchTest
import com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses
import com.tngtech.archunit.library.dependencies.SlicesRuleDefinition
import com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices
import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@AnalyzeClasses(packagesOf = [OnionArchitectureTest::class])
internal class OnionArchitectureTest {
@ArchTest
val `there are no package cycles` =
SlicesRuleDefinition.slices()
.matching("$BASE_PACKAGE.(**)..")
.should()
.beFreeOfCycles()
@ArchTest
val `the domain model does not have outgoing dependencies` =
noClasses()
.that()
.resideInAPackage("$DOMAIN_MODEL_PACKAGE..")
.should()
.accessClassesThat()
.resideInAnyPackage("$DOMAIN_SERVICE_PACKAGE..", "$APPLICATION_PACKAGE..", "$ADAPTER_PACKAGE..")
@ArchTest
val `the domain does not access the application and adapters` =
noClasses()
.that()
.resideInAPackage("$DOMAIN_PACKAGE..")
.should()
.accessClassesThat()
.resideInAnyPackage("$APPLICATION_PACKAGE..", "$ADAPTER_PACKAGE..")
@ArchTest
val `the application does not access the adapters` =
noClasses()
.that()
.resideInAPackage("$APPLICATION_PACKAGE..")
.should()
.accessClassesThat()
.resideInAPackage("$ADAPTER_PACKAGE..")
@ArchTest
val `one adapter should not access another adapter` =
slices()
.matching("$ADAPTER_PACKAGE.(*)")
.should().notDependOnEachOther()
companion object {
private val BASE_PACKAGE = OnionArchitectureTest::class.java.`package`.name
private val DOMAIN_PACKAGE = "$BASE_PACKAGE.domain"
private val DOMAIN_MODEL_PACKAGE = "$DOMAIN_PACKAGE.model"
private val DOMAIN_SERVICE_PACKAGE = "$DOMAIN_PACKAGE.service"
private val APPLICATION_PACKAGE = "$BASE_PACKAGE.application"
private val ADAPTER_PACKAGE = "$BASE_PACKAGE.adapter"
}
}