确定框架需要存在类的空构造函数,例如Jakartaee无国籍服务,但他们没有适当的依赖项注入。我想用类似
DoNotUse
注释(有原因)的内容来注释这些构造函数,然后使用Archunit检查是否没有人实际使用它。
像这样的东西:
ArchRuleDefinition.noConstructors()
.that()
.areAnnotatedWith(DoNotUse.class)
.should()
.beCalled();
但不存在Afaik。我现在通过添加永不匹配的条件来解决它:
beCalled
beUsed
??
您可以使用方便的工厂方法使用自定义条件:
ArchRuleDefinition.constructors()
.that()
.areAnnotatedWith(DoNotUse.class)
.should()
.onlyBeCalled()
.byClassesThat()
.haveSimpleName("ThisOnPurposeDoesNotMatchAnything");
S和beCalled
S。
neverBeCalled