Skip to content

Commit 7fcba71

Browse files
committed
ArchUnit
1 parent 5ee6c20 commit 7fcba71

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
33
val springBootVersion = "3.2.2"
44
val embeddedRedisVersion = "1.4.1"
55
val mockkVersion = "1.13.9"
6+
val archunitVersion = "1.2.1"
67

78
plugins {
89
val springDependencyManagementVersion = "1.1.4"
@@ -60,6 +61,7 @@ dependencies {
6061
testImplementation("org.springframework.boot:spring-boot-starter-data-redis")
6162
testImplementation("org.springframework.boot:spring-boot-starter-test")
6263
testImplementation("io.mockk:mockk:$mockkVersion")
64+
testImplementation("com.tngtech.archunit:archunit-junit5:$archunitVersion")
6365
}
6466

6567
tasks.withType<KotlinCompile> {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package io.github.tobi.laa.spring.boot.embedded.redis
2+
3+
import com.tngtech.archunit.core.importer.ImportOption.DoNotIncludeTests
4+
import com.tngtech.archunit.junit.AnalyzeClasses
5+
import com.tngtech.archunit.junit.ArchTest
6+
import com.tngtech.archunit.lang.syntax.ArchRuleDefinition.fields
7+
import com.tngtech.archunit.library.GeneralCodingRules.*
8+
9+
/**
10+
* Some general coding rules, in broad parts copied over from the ArchUnit examples.
11+
*/
12+
@Suppress("Unused")
13+
@AnalyzeClasses(packagesOf = [CodingRulesTest::class], importOptions = [DoNotIncludeTests::class])
14+
internal class CodingRulesTest {
15+
16+
@ArchTest
17+
private val `No classes should access standard streams` = NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS
18+
19+
@ArchTest
20+
private val `No classes should throw generic exceptions` = NO_CLASSES_SHOULD_THROW_GENERIC_EXCEPTIONS
21+
22+
@ArchTest
23+
private val `No classes should use Java 2 platform's core logging facilities` =
24+
NO_CLASSES_SHOULD_USE_JAVA_UTIL_LOGGING
25+
26+
@ArchTest
27+
private val `Loggers should be private and static and final` =
28+
fields().that()
29+
.haveRawType("org.slf4j.Logger")
30+
.should().bePrivate()
31+
.andShould().beStatic()
32+
.andShould().beFinal()
33+
.`as`("Loggers should private static final.")
34+
.because("That is a convention for this project.")
35+
.allowEmptyShould(true)
36+
37+
@ArchTest
38+
private val `No classes should use Joda time` = NO_CLASSES_SHOULD_USE_JODATIME
39+
40+
@ArchTest
41+
private val `No classes should use field injection` = NO_CLASSES_SHOULD_USE_FIELD_INJECTION
42+
}

0 commit comments

Comments
 (0)