-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add architecture test to ensure correct usage of TraceLink class
- Loading branch information
Showing
2 changed files
with
35 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
30 changes: 30 additions & 0 deletions
30
...ework/common/src/test/java/edu/kit/kastel/mcse/ardoco/core/TraceLinkArchitectureTest.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,30 @@ | ||
package edu.kit.kastel.mcse.ardoco.core; | ||
|
||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods; | ||
|
||
import com.tngtech.archunit.base.DescribedPredicate; | ||
import com.tngtech.archunit.core.domain.JavaClass; | ||
import com.tngtech.archunit.junit.AnalyzeClasses; | ||
import com.tngtech.archunit.junit.ArchTest; | ||
import com.tngtech.archunit.lang.ArchRule; | ||
|
||
import edu.kit.kastel.mcse.ardoco.core.api.tracelink.TraceLink; | ||
|
||
@AnalyzeClasses(packages = "edu.kit.kastel.mcse.ardoco") | ||
class TraceLinkArchitectureTest { | ||
private static final DescribedPredicate<JavaClass> isSubclassOfTraceLink = new DescribedPredicate<>("subclass of " + TraceLink.class) { | ||
@Override | ||
public boolean test(JavaClass clazz) { | ||
return clazz.isAssignableTo(TraceLink.class); | ||
} | ||
}; | ||
|
||
@ArchTest | ||
static final ArchRule onlyTraceLinkAsReturnType = methods().that() | ||
.haveRawReturnType(isSubclassOfTraceLink) | ||
.and() | ||
.areNotPrivate() | ||
.should() | ||
.haveRawReturnType(TraceLink.class) | ||
.because("the specific subclasses of TraceLink shall not be used as return type in non-private methods"); | ||
} |