我正在使用JUnit 5评估ArchUnit 0.13.1,并尝试编写如下规则:
@ArchTest
private final ArchRule annotationInheritance = ArchRuleDefinition.classes()
.that().areAnnotatedWith(MyAnnotation.class)
.should().onlyHaveSubclassesThat().areAnnotatedWith(MyAnnotation.class);问题是ArchUnit中没有"onlyHaveSubclassesThat()“方法。我相信可能还有另一种方法来实现同样的目标,但如何实现呢?
发布于 2020-09-19 22:07:29
您可以将检查应用于继承某个类的子类:
classes()
.that().areAssignableTo(CanBeAnnotated.Predicates.annotatedWith(MyAnnotation.class))
.should().beAnnotatedWith(MyAnnotation.class);https://stackoverflow.com/questions/61955869
复制相似问题