-
Notifications
You must be signed in to change notification settings - Fork 1
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
Stefan
committed
Jan 15, 2024
1 parent
77e1a88
commit 98c48bc
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
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
50 changes: 50 additions & 0 deletions
50
backend/src/test/java/com/github/binpastes/paste/api/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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.github.binpastes.paste.api; | ||
|
||
import com.github.binpastes.paste.domain.Paste; | ||
import com.tngtech.archunit.core.importer.ClassFileImporter; | ||
import com.tngtech.archunit.core.importer.ImportOption; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; | ||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noMethods; | ||
|
||
class ArchitectureTest { | ||
|
||
private static final ImportOption DO_NOT_INCLUDE_MAVEN_TESTS = location -> !location.contains("/test-classes/"); | ||
|
||
@Test | ||
void domainClassNeverRendered() { | ||
var importedClasses = new ClassFileImporter() | ||
.withImportOption(DO_NOT_INCLUDE_MAVEN_TESTS) | ||
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_JARS) | ||
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS) | ||
.importPackages("com.github.binpastes.paste.api"); | ||
|
||
var rule = noMethods() | ||
.that() | ||
.areDeclaredInClassesThat() | ||
.resideInAPackage("com.github.binpastes.paste.api") | ||
.should() | ||
.haveRawReturnType(Paste.class); | ||
|
||
rule.check(importedClasses); | ||
} | ||
|
||
@Test | ||
void injectionsMindArchitecturalBorders() { | ||
var importedClasses = new ClassFileImporter() | ||
.withImportOption(DO_NOT_INCLUDE_MAVEN_TESTS) | ||
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_JARS) | ||
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS) | ||
.importPackages("com.github.binpastes.paste.api"); | ||
|
||
var rule = noClasses() | ||
.that() | ||
.resideInAPackage("com.github.binpastes.paste.api") | ||
.should() | ||
.dependOnClassesThat().areAnnotatedWith(Repository.class); | ||
|
||
rule.check(importedClasses); | ||
} | ||
} |