Skip to content

Commit

Permalink
Added new ArchUnit rules
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-schnell committed Mar 30, 2024
1 parent 35c5dc7 commit 4e9d94d
Show file tree
Hide file tree
Showing 18 changed files with 207 additions and 82 deletions.
3 changes: 3 additions & 0 deletions core/src/main/java/org/fuin/ddd4j/core/AggregateNoCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
*/
package org.fuin.ddd4j.core;

import org.fuin.utils4j.TestOmitted;

/**
* Never caches anything.
*
* @param <AGGREGATE>
* Type of the aggregate.
*/
@TestOmitted("Nothing useful to test")
public final class AggregateNoCache<AGGREGATE> implements AggregateCache<AGGREGATE> {

@Override
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/fuin/ddd4j/core/Ddd4JUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
*/
package org.fuin.ddd4j.core;

import org.fuin.utils4j.TestOmitted;

/**
* Utility methods and constants.
*/
@TestOmitted("Currently nothing to test")
public final class Ddd4JUtils {

/**
Expand Down
11 changes: 0 additions & 11 deletions core/src/test/java/org/fuin/ddd4j/core/AggregateNoCacheTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ArchitectureTest {
"org.fuin.objects4j.common..",
"org.fuin.objects4j.core..",
"org.fuin.objects4j.ui..",
"org.fuin.utils4j.jandex..",
"org.fuin.utils4j..",
"org.jboss.jandex..",
"org.slf4j..");

Expand Down
12 changes: 2 additions & 10 deletions core/src/test/java/org/fuin/ddd4j/core/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.tngtech.archunit.junit.ArchIgnore;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
import org.fuin.units4j.archunit.Units4JConditions;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static org.fuin.units4j.archunit.AllTopLevelClassesHaveATestCondition.haveACorrespondingClassEndingWith;
Expand All @@ -30,16 +31,7 @@
class BaseTest {

@ArchTest
static final ArchRule all_classes_should_have_tests =
classes()
.that()
.areTopLevelClasses()
.and().areNotInterfaces()
.and().areNotRecords()
.and().areNotEnums()
.and().doNotHaveModifier(JavaModifier.ABSTRACT)
.and().areNotAnnotatedWith(ArchIgnore.class)
.should(haveACorrespondingClassEndingWith("Test"));
static final ArchRule all_classes_should_have_tests = Units4JConditions.ALL_CLASSES_SHOULD_HAVE_TESTS;

}

11 changes: 0 additions & 11 deletions core/src/test/java/org/fuin/ddd4j/core/Ddd4JUtilsTest.java

This file was deleted.

6 changes: 6 additions & 0 deletions esc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.fuin</groupId>
<artifactId>utils4j</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-mem</artifactId>
Expand Down
12 changes: 2 additions & 10 deletions esc/src/test/java/org/fuin/ddd4j/esc/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.tngtech.archunit.junit.ArchIgnore;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
import org.fuin.units4j.archunit.Units4JConditions;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static org.fuin.units4j.archunit.AllTopLevelClassesHaveATestCondition.haveACorrespondingClassEndingWith;
Expand All @@ -30,16 +31,7 @@
class BaseTest {

@ArchTest
static final ArchRule all_classes_should_have_tests =
classes()
.that()
.areTopLevelClasses()
.and().areNotInterfaces()
.and().areNotRecords()
.and().areNotEnums()
.and().doNotHaveModifier(JavaModifier.ABSTRACT)
.and().areNotAnnotatedWith(ArchIgnore.class)
.should(haveACorrespondingClassEndingWith("Test"));
static final ArchRule all_classes_should_have_tests = Units4JConditions.ALL_CLASSES_SHOULD_HAVE_TESTS;

}

3 changes: 2 additions & 1 deletion esc/src/test/java/org/fuin/ddd4j/esc/VendorRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
import org.fuin.ddd4j.jsonbtestmodel.Vendor;
import org.fuin.ddd4j.jsonbtestmodel.VendorId;
import org.fuin.esc.api.EventStore;
import org.fuin.utils4j.TestOmitted;

import java.util.List;

/**
* Implements a repository that is capable of storing vendors.
*/
@ArchIgnore
@TestOmitted("Only a test class")
public final class VendorRepository extends EventStoreRepository<VendorId, Vendor> {

/**
Expand Down
12 changes: 2 additions & 10 deletions jaxb/src/test/java/org/fuin/ddd4j/jaxb/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.tngtech.archunit.junit.ArchIgnore;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
import org.fuin.units4j.archunit.Units4JConditions;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static org.fuin.units4j.archunit.AllTopLevelClassesHaveATestCondition.haveACorrespondingClassEndingWith;
Expand All @@ -30,16 +31,7 @@
class BaseTest {

@ArchTest
static final ArchRule all_classes_should_have_tests =
classes()
.that()
.areTopLevelClasses()
.and().areNotInterfaces()
.and().areNotRecords()
.and().areNotEnums()
.and().doNotHaveModifier(JavaModifier.ABSTRACT)
.and().areNotAnnotatedWith(ArchIgnore.class)
.should(haveACorrespondingClassEndingWith("Test"));
static final ArchRule all_classes_should_have_tests = Units4JConditions.ALL_CLASSES_SHOULD_HAVE_TESTS;

}

6 changes: 6 additions & 0 deletions jsonb-testmodel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
<artifactId>ddd-4-java-core</artifactId>
</dependency>

<dependency>
<groupId>org.fuin.ddd4j</groupId>
<artifactId>ddd-4-java-junit</artifactId>
</dependency>


<dependency>
<groupId>org.fuin.objects4j</groupId>
<artifactId>objects4j-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package org.fuin.ddd4j.jsonbtestmodel;

import com.tngtech.archunit.core.domain.JavaModifier;
import com.tngtech.archunit.core.importer.ImportOption;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
import org.fuin.ddd4j.core.DomainEvent;
import org.fuin.ddd4j.core.EntityId;
import org.fuin.ddd4j.core.EntityType;
import org.fuin.ddd4j.core.HasEntityTypeConstant;
import org.fuin.esc.api.HasSerializedDataTypeConstant;
import org.fuin.objects4j.common.HasPublicStaticIsValidMethod;
import org.fuin.objects4j.common.HasPublicStaticValueOfMethod;
import org.fuin.ddd4j.junit.Ddd4JConditions;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static com.tngtech.archunit.library.DependencyRules.NO_CLASSES_SHOULD_DEPEND_UPPER_PACKAGES;
Expand Down Expand Up @@ -49,17 +43,9 @@ public class ArchitectureTest {
"org.fuin.objects4j.ui..");

@ArchTest
static final ArchRule verify_domain_events = classes()
.that().implement(DomainEvent.class)
.and().doNotHaveModifier(JavaModifier.ABSTRACT)
.should().beAnnotatedWith(HasSerializedDataTypeConstant.class);
static final ArchRule verify_domain_events = Ddd4JConditions.DOMAIN_EVENT_RULES;

@ArchTest
static final ArchRule verify_entity_ids = classes()
.that().areAssignableTo(EntityId.class)
.and().doNotHaveModifier(JavaModifier.ABSTRACT)
.should().beAnnotatedWith(HasPublicStaticValueOfMethod.class)
.andShould().beAnnotatedWith(HasPublicStaticIsValidMethod.class)
.andShould().beAnnotatedWith(HasEntityTypeConstant.class);
static final ArchRule verify_entity_ids = Ddd4JConditions.ENTITY_ID_RULES;

}
12 changes: 2 additions & 10 deletions jsonb/src/test/java/org/fuin/ddd4j/jsonb/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.tngtech.archunit.junit.ArchIgnore;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
import org.fuin.units4j.archunit.Units4JConditions;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static org.fuin.units4j.archunit.AllTopLevelClassesHaveATestCondition.haveACorrespondingClassEndingWith;
Expand All @@ -30,16 +31,7 @@
class BaseTest {

@ArchTest
static final ArchRule all_classes_should_have_tests =
classes()
.that()
.areTopLevelClasses()
.and().areNotInterfaces()
.and().areNotRecords()
.and().areNotEnums()
.and().doNotHaveModifier(JavaModifier.ABSTRACT)
.and().areNotAnnotatedWith(ArchIgnore.class)
.should(haveACorrespondingClassEndingWith("Test"));
static final ArchRule all_classes_should_have_tests = Units4JConditions.ALL_CLASSES_SHOULD_HAVE_TESTS;

}

3 changes: 2 additions & 1 deletion jsonb/src/test/java/org/fuin/ddd4j/jsonb/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
import org.eclipse.yasson.FieldAccessStrategy;
import org.fuin.ddd4j.core.EntityIdFactory;
import org.fuin.ddd4j.jsonbtest.JsonbTestEntityIdFactory;
import org.fuin.utils4j.TestOmitted;

import java.nio.charset.StandardCharsets;
import java.util.List;

/**
* Utils for the package.
*/
@ArchIgnore
@TestOmitted("Only a test class")
final class TestUtils {

private static final EntityIdFactory ENTITY_ID_FACTORY = new JsonbTestEntityIdFactory();
Expand Down
6 changes: 6 additions & 0 deletions junit/ddd-4-java-junit.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="a69938dc-ebda-4a65-9b67-d28711ef8198" />
</component>
</module>
110 changes: 110 additions & 0 deletions junit/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.fuin.ddd4j</groupId>
<artifactId>ddd-4-java</artifactId>
<version>0.6.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>ddd-4-java-junit</artifactId>

<dependencies>

<!-- compile -->

<dependency>
<groupId>org.fuin.ddd4j</groupId>
<artifactId>ddd-4-java-core</artifactId>
</dependency>

<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-api</artifactId>
</dependency>

<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit</artifactId>
</dependency>

<dependency>
<groupId>org.fuin.objects4j</groupId>
<artifactId>objects4j-common</artifactId>
</dependency>

<dependency>
<groupId>org.fuin.objects4j</groupId>
<artifactId>objects4j-junit</artifactId>
</dependency>

<!-- test -->

<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>

<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>

<plugin>
<groupId>io.smallrye</groupId>
<artifactId>jandex-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jdeps-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<ignoredUnusedDeclaredDependencies>
<ignoredUnusedDeclaredDependency>jakarta.el:jakarta.el-api</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>org.glassfish:jakarta.el</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>org.hibernate.validator:hibernate-validator</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>org.fuin.objects4j:objects4j-junit</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>com.tngtech.archunit:archunit-junit5</ignoredUnusedDeclaredDependency>
</ignoredUnusedDeclaredDependencies>
<ignoredUsedUndeclaredDependencies>
<ignoredUsedUndeclaredDependency>com.tngtech.archunit:archunit-junit5-api</ignoredUsedUndeclaredDependency>
</ignoredUsedUndeclaredDependencies>
</configuration>
</plugin>

</plugins>

</build>

</project>
Loading

0 comments on commit 4e9d94d

Please sign in to comment.