Skip to content

Commit

Permalink
Add architecture test to ensure correct usage of TraceLink class
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuchss committed Nov 29, 2024
1 parent 89f8921 commit 6586bb6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions framework/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,10 @@
<artifactId>sqlite-jdbc</artifactId>
<version>3.46.0.1</version>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
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");
}

0 comments on commit 6586bb6

Please sign in to comment.