Another version of Testing aggregate consistency using ArchUnit ①
@ArchTest
static ArchRule aggregate_object_only_be_accessed_from_root =
classes()
.that().resideInAPackage("com.example.domain")
.should().onlyBeAccessed().byClassesThat(new DescribedPredicate<JavaClass>("is AggregateRoot") {
@Override
public boolean apply(JavaClass input) {
return input.getAnnotations().stream().anyMatch(a -> a.toString().equals("AggregateRoot"));
}
});
If @AggregateRoot
is added to the aggregate root, it can be judged simply.
The place to extract annotations should be able to be written a little more beautifully ...
Recommended Posts