如何编写一个不应调用构造函数或方法的Archunit规范?

问题描述 投票:0回答:1

确定框架需要存在类的空构造函数,例如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
java archunit
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.