I have a class that looks like this:
public class A {
private B b1 = new B();
private C c = new C();
private B b2;
}
I want to write an ArchUnit test that finds all the fields in class A that are of type B and that are initialized. So in this case, just field ‘b1’.
I wrote a test like this, but can’t finish it. Is this even possible?
@ArchTest
void dontInitialize(JavaClasses classesToTest) {
noFields().that().haveRawType(DescribedPredicate.describe("that is a B object", type -> {
return type.isAssignableTo(B.class);
})).should(new ArchCondition<JavaField>("") {
@Override
public void check(JavaField javaField, ConditionEvents conditionEvents) {
// ???
}
});
}