Test the integrity of the aggregation using ArchUnit ②

Let's test that "references to other aggregates are made via Id".

Test code

    @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");
            }
        });

We are only testing that we are not directly referencing the aggregate route. You can make it a little more strict by determining the field name like endWith ~ ("Id") .

It is difficult to determine the aggregation route mechanically.

If you have something like @AggregateRoot, you'll be happy.

Recommended Posts

Test the integrity of the aggregation using ArchUnit ②
Test the integrity of the aggregation using ArchUnit ③
Unit test architecture using ArchUnit
[Java] [Spring] Test the behavior of the logger
Using Elasticsearch Java-API (BulkRequest registration) [Additional notes]
I tried using Elasticsearch API in Java
Test the integrity of the aggregation using ArchUnit ②
Status monitoring of java application using Elasticsearch
Test the integrity of the aggregation using ArchUnit ③
RSpec-Results of reviewing the test code for'users validation'
Story of test automation using Appium [Android / java]
I tried using the profiler of IntelliJ IDEA
Test the response JSON of the REST API created in Spring MVC using AssertJ in MockMvc
Json Request in Unit Test of Controller using MockMvc
I tried using the Server Push function of Servlet 4.0
CI the architecture of Java / Kotlin applications with ArchUnit
[Rails] Test of star evaluation function using Raty [Rspec]
Get the name of the test case in the JUnit test class
Test the contents of an Excel file with JUnit
Rails6: Input the initial data of ActionText using seed
Output of the day of the week using Ruby's Date class
Limit the number of threads using Java's Executor Service
Are you using the default method of the interface properly?
The first step to using Xib instead of StoryBoard
The story of making Dr. Oakid using LINE BOT
Try using the query attribute of Ruby on Rails
The world of clara-rules (2)
Judgment of the calendar
The world of clara-rules (4)
Example of using vue.config.js
The world of clara-rules (1)
The world of clara-rules (3)
Summary of using FragmentArgs
The world of clara-rules (5)
The idea of quicksort
Summary of using DBFlow
The idea of jQuery
[Enum] Let's improve the readability of data by using rails enum
[Rails] Register by attribute of the same model using Devise
Transition using the header image of CardView as it is
When using the constructor of Java's Date class, the date advances by 1900.
Check the status of Java application without using monitoring tool
[Ruby] Creating code using the concept of classes and instances
[Java] Try editing the elements of the Json string using the library
[Ruby] Display today's day of the week using Date class
Takashi! I've got rice! Notification of rice using the Ovserver pattern
How to mock some methods of the class under test
The story of pushing Java to Heroku using the BitBucket pipeline
About the default behavior of decimal point rounding using java.text.NumberFormat
[Apache Tomcat] The story of using Apache OpenWebBeans to enable CDI
Test the behavior of the log output logger when using an external logging API such as SLF4J