-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ArchRule: Prevent ForEach (as not functional)
- Loading branch information
Showing
4 changed files
with
53 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/test/java/edu/kit/kastel/sdq/artemis4j/ArchitectureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* Licensed under EPL-2.0 2024. */ | ||
package edu.kit.kastel.sdq.artemis4j; | ||
|
||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.*; | ||
|
||
import java.util.List; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Stream; | ||
|
||
import com.tngtech.archunit.junit.AnalyzeClasses; | ||
import com.tngtech.archunit.junit.ArchTest; | ||
import com.tngtech.archunit.lang.ArchRule; | ||
|
||
@AnalyzeClasses(packages = "edu.kit.kastel.sdq.artemis4j") | ||
class ArchitectureTest { | ||
|
||
@ArchTest | ||
static final ArchRule noForEachInCollectionsOrStream = noClasses() | ||
.should() | ||
.callMethod(Stream.class, "forEach", Consumer.class) | ||
.orShould() | ||
.callMethod(Stream.class, "forEachOrdered", Consumer.class) | ||
.orShould() | ||
.callMethod(List.class, "forEach", Consumer.class) | ||
.orShould() | ||
.callMethod(List.class, "forEachOrdered", Consumer.class) | ||
.because("Lambdas should be functional. ForEach is typically used for side-effects."); | ||
} |