Reputation: 123
Is there way to test that classes extends specific class in ArchUnit test?
I have 3 classes:
I need to validate that ClassC extends ClassA. The following test
ArchRuleDefinition.classes()
.that()
.haveSimpleName("ClassC")
.should()
.beAssignableTo("ClassA")
.check(classes);
fails with violation error
Architecture Violation [Priority: MEDIUM] - Rule 'classes that have simple name 'ClassC' should be assignable to ClassA' was violated (1 times):
Class <ClassC> is not assignable to ClassA in ...
Upvotes: 0
Views: 1402
Reputation: 3142
You can only use beAssignableTo("ClassA")
if ClassA
resides in the default package.
In general, you have to use fully qualified class name, i.e. ClassA.class.getName()
.
If ClassA
is available on the classpath, I'd use beAssignableTo(ClassA.class)
.
Upvotes: 1