0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

アーキテクチャテストAdvent Calendar 2020

Day 20

集約の整合性についてArchUnitを用いてテストする③

Posted at

集約の整合性について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"));
            }
        });

@AggregateRootが集約ルートに付与されていればシンプルに判定できる。
アノテーション抽出するところはもう少しきれいに書けるはず・・・

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?