forked from TNG/ArchUnit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test demonstrating a rule shared between projects
run the following command > ./gradlew :archunit-example:example-junit4:test --tests "*.ServiceRulesTest" -P example Inspect the test result file at > archunit-example/example-junit4/build/reports/tests/test/index.html You will find a duplicated report for one of the projects, and the failure of the other project is lost. Issue: TNG#452 Signed-off-by: Christian Semrau <[email protected]>
- Loading branch information
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...e-junit4/src/test/java/com/tngtech/archunit/exampletest/junit4/platform/ServiceRules.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,19 @@ | ||
package com.tngtech.archunit.exampletest.junit4.platform; | ||
|
||
import com.tngtech.archunit.example.layers.MyService; | ||
import com.tngtech.archunit.junit.ArchTest; | ||
import com.tngtech.archunit.lang.ArchRule; | ||
|
||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; | ||
|
||
/** | ||
* Shared rule, to be referenced in tests of "projectA" and "projectB". | ||
*/ | ||
public class ServiceRules { | ||
@ArchTest | ||
public static ArchRule services_should_be_prefixed = | ||
classes() | ||
.that().resideInAPackage("..service..") | ||
.and().areAnnotatedWith(MyService.class) | ||
.should().haveSimpleNameStartingWith("Service"); | ||
} |
21 changes: 21 additions & 0 deletions
21
...nit4/src/test/java/com/tngtech/archunit/exampletest/junit4/projectA/ServiceRulesTest.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,21 @@ | ||
package com.tngtech.archunit.exampletest.junit4.projectA; | ||
|
||
import com.tngtech.archunit.exampletest.junit4.Example; | ||
import com.tngtech.archunit.exampletest.junit4.platform.ServiceRules; | ||
import com.tngtech.archunit.junit.AnalyzeClasses; | ||
import com.tngtech.archunit.junit.ArchRules; | ||
import com.tngtech.archunit.junit.ArchTest; | ||
import com.tngtech.archunit.junit.ArchUnitRunner; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* Runs the shared rules for "projectA" only. | ||
*/ | ||
@Category(Example.class) | ||
@RunWith(ArchUnitRunner.class) | ||
@AnalyzeClasses(packages = "com.tngtech.archunit.example.projectA") | ||
public class ServiceRulesTest { | ||
@ArchTest | ||
private final ArchRules service_rules = ArchRules.in(ServiceRules.class); | ||
} |
21 changes: 21 additions & 0 deletions
21
...nit4/src/test/java/com/tngtech/archunit/exampletest/junit4/projectB/ServiceRulesTest.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,21 @@ | ||
package com.tngtech.archunit.exampletest.junit4.projectB; | ||
|
||
import com.tngtech.archunit.exampletest.junit4.Example; | ||
import com.tngtech.archunit.exampletest.junit4.platform.ServiceRules; | ||
import com.tngtech.archunit.junit.AnalyzeClasses; | ||
import com.tngtech.archunit.junit.ArchRules; | ||
import com.tngtech.archunit.junit.ArchTest; | ||
import com.tngtech.archunit.junit.ArchUnitRunner; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* Runs the shared rules for "projectB" only. | ||
*/ | ||
@Category(Example.class) | ||
@RunWith(ArchUnitRunner.class) | ||
@AnalyzeClasses(packages = "com.tngtech.archunit.example.projectB") | ||
public class ServiceRulesTest { | ||
@ArchTest | ||
private final ArchRules service_rules = ArchRules.in(ServiceRules.class); | ||
} |
10 changes: 10 additions & 0 deletions
10
...example-plain/src/main/java/com/tngtech/archunit/example/projectA/service/MyServiceA.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,10 @@ | ||
package com.tngtech.archunit.example.projectA.service; | ||
|
||
import com.tngtech.archunit.example.layers.MyService; | ||
|
||
/** | ||
* For Demo purposes only. | ||
*/ | ||
@MyService | ||
public class MyServiceA { | ||
} |
10 changes: 10 additions & 0 deletions
10
...example-plain/src/main/java/com/tngtech/archunit/example/projectB/service/MyServiceB.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,10 @@ | ||
package com.tngtech.archunit.example.projectB.service; | ||
|
||
import com.tngtech.archunit.example.layers.MyService; | ||
|
||
/** | ||
* For Demo purposes only. | ||
*/ | ||
@MyService | ||
public class MyServiceB { | ||
} |