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 13

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

Posted at

「他の集約への参照はId経由で行う」ことをテストしてみる。

テストコード

    @ArchTest
    static ArchRule only_access_through_id_when_depend_on_another_aggregate_root =
        classes()
            .that().resideInAPackage("com.example.domain")
            .and().haveSimpleName("HogeRoot")
            .should().onlyAccessFieldsThat(new DescribedPredicate<JavaField>("not depend on another aggregate root object") {
            @Override
            public boolean apply(JavaField input) {
                return !input.getClass().getSimpleName().equals("FugaRoot");
            }
        });

集約ルートを直接参照していないことだけテストしている。
フィールド名をendWith~("Id")みたいに判別すればもう少し厳密にできる。

集約ルートを機械的に判別するのが辛い。

@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?