Given that I have an arch unit test like this:
package org.example;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import org.junit.jupiter.api.Test;
public class RecordTest
{
@Test
public void recordTest() {
var javaClasses = new ClassFileImporter().importPackages("org.example");
classes().that()
.haveNameMatching("(.*)Record")
.should()
.beRecords()
.because("they should be simple data structures")
.check(javaClasses);
}
}
And a record like this in my project:
package org.example;
public record EmptyRecord()
{
}
When I run the arch unit test, then a violation is reported, even though EmptyRecord is a valid (but useless) Java 14 record:
Architecture Violation [Priority: MEDIUM] - Rule 'classes that have name matching '(.*)Record' should be records, because they should be simple data structures' was violated (1 times):
Class <org.example.EmptyRecord> is no record in (EmptyRecord.java:0)
java.lang.AssertionError: Architecture Violation [Priority: MEDIUM] - Rule 'classes that have name matching '(.*)Record' should be records, because they should be simple data structures' was violated (1 times):
Class <org.example.EmptyRecord> is no record in (EmptyRecord.java:0)
at com.tngtech.archunit.lang.ArchRule$Assertions.assertNoViolation(ArchRule.java:94)
at com.tngtech.archunit.lang.ArchRule$Assertions.check(ArchRule.java:86)
at com.tngtech.archunit.lang.ArchRule$Factory$SimpleArchRule.check(ArchRule.java:165)
at org.example.RecordTest.recordTest(RecordTest.java:20)
When the record is extended with a parameter, then the violation is resolved:
package org.example;
public record EmptyRecord(String someValue)
{
}
A full example to reproduce the issue can be found here.
Given that I have an arch unit test like this:
And a record like this in my project:
When I run the arch unit test, then a violation is reported, even though
EmptyRecordis a valid (but useless) Java 14 record:When the record is extended with a parameter, then the violation is resolved:
A full example to reproduce the issue can be found here.