Skip to content

Commit

Permalink
Updated ArchUnit and added check for application/domain code accessin…
Browse files Browse the repository at this point in the history
…g random/shuffle code.

Fixed RandomShuffler by moving it to the web admin adapter where it's used.
  • Loading branch information
tedyoung committed May 4, 2024
1 parent dca23de commit cd95300
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<version>1.2.1</version>
<version>1.3.0</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.jitterted.mobreg.adapter.in.web.admin;

import com.jitterted.mobreg.application.EnsembleTimerHolder;
import com.jitterted.mobreg.application.port.RandomShuffler;
import com.jitterted.mobreg.domain.EnsembleId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jitterted.mobreg.application.port;
package com.jitterted.mobreg.adapter.in.web.admin;

import com.jitterted.mobreg.application.port.Shuffler;
import com.jitterted.mobreg.domain.Member;

import java.util.Collections;
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/com/jitterted/mobreg/HexagonalArchitectureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Random;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
import static com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices;
Expand Down Expand Up @@ -64,6 +67,21 @@ void domainAndApplicationMustNotAccessSystemTime() {
.importPackages("com.jitterted.mobreg"));
}

@Test
void domainAndApplicationMustNotAccessRandom() {
noClasses()
.that().resideInAPackage("..domain..")
.or().resideInAPackage("..application..")

.should().callMethod(Collections.class, "shuffle", List.class)
.orShould().dependOnClassesThat().areAssignableTo(Random.class)

.as("Neither Application nor Domain should access Random or Random-related code (e.g., Collections.shuffle).")
.check(new ClassFileImporter()
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)
.importPackages("com.jitterted.mobreg"));
}

private JavaClasses productionAndTestClasses() {
return new ClassFileImporter().importPackages("com.jitterted.mobreg");
}
Expand Down

0 comments on commit cd95300

Please sign in to comment.