Open tomek-w-k opened 1 year ago
The synthetic class com.app.archunittest.service.DummyService$1
doesn't have a simple name (but ""
).
Technically, you could use orShould().haveNameMatching(".*\\.Service\\$1")
, but you probably want to use the solution classes().that().doNotHaveModifier(JavaModifier.SYNTHETIC)
from https://github.com/TNG/ArchUnit/issues/1011#issuecomment-1336332226.
SYNTHETIC doesn't work for me, but i've noticed that these generated classes are recognised as anonymous. As a workaround i use .areNotAnonymousClasses() to exclude them from the evaluation
In a Spring Boot 2.7 project I implemented the following code:
Then, with ArchUnit 1.0.1 I created a test for it:
The test fails with an error:
Then I created a custom annotation @IgnoreArchUnitTest:
and applied it to my service class. Modifiled the test:
Service class should now be ignored by the test, but the error message I got was almost the same:
Ok, the error message rightly says that the Class <com.app.archunittest.service.DummyService$1> does not have simple name ending with 'Service'. Thus, I removed the @IgnoreArchUnitTest annotation both from the service class and from the test. Added a new condition to the test for checking the "Service$1" suffix:
Now, the error says:
"Class <com.app.archunittest.service.DummyService$1> does not have simple name ending with 'Service$1'" That's interesting...
However, when I modified my service method as below:
by replacing enum values with corresponding strings within the switch statement, the test passed successfully.
Is that a correct behavior of that test or maybe I did something wrong?