Skip to content

Commit d041c6d

Browse files
committed
GH-31 - Polishing.
Added unit tests for the test execution conditions. Add JUnit module to the BOM. Moved the jGit version into a managed property in the root pom.xml.
1 parent 8cf3920 commit d041c6d

32 files changed

+1227
-392
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<archunit.version>1.3.0</archunit.version>
3838
<artifactory-maven-plugin.version>3.6.2</artifactory-maven-plugin.version>
3939
<flapdoodle-mongodb.version>4.14.0</flapdoodle-mongodb.version>
40+
<jgit.version>6.10.0.202406032230-r</jgit.version>
4041
<jgrapht.version>1.5.2</jgrapht.version>
4142
<jmolecules-bom.version>2023.1.4</jmolecules-bom.version>
4243
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

spring-modulith-bom/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@
9999
<artifactId>spring-modulith-events-tests</artifactId>
100100
<version>1.3.0-SNAPSHOT</version>
101101
</dependency>
102+
<dependency>
103+
<groupId>org.springframework.modulith</groupId>
104+
<artifactId>spring-modulith-junit</artifactId>
105+
<version>1.3.0-SNAPSHOT</version>
106+
</dependency>
102107
<dependency>
103108
<groupId>org.springframework.modulith</groupId>
104109
<artifactId>spring-modulith-moments</artifactId>

spring-modulith-examples/spring-modulith-example-full/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@
6363
<artifactId>spring-boot-configuration-processor</artifactId>
6464
<optional>true</optional>
6565
</dependency>
66+
6667
<dependency>
6768
<groupId>org.springframework.modulith</groupId>
6869
<artifactId>spring-modulith-junit</artifactId>
69-
<version>1.3.0-SNAPSHOT</version>
7070
<scope>test</scope>
7171
</dependency>
72+
7273
</dependencies>
7374

7475
</project>

spring-modulith-integration-test/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@
5959

6060
<!-- Test -->
6161

62+
<dependency>
63+
<groupId>org.springframework.modulith</groupId>
64+
<artifactId>spring-modulith-junit</artifactId>
65+
<version>${project.version}</version>
66+
<scope>test</scope>
67+
</dependency>
68+
6269
<dependency>
6370
<groupId>org.springframework.boot</groupId>
6471
<artifactId>spring-boot-starter-test</artifactId>

spring-modulith-integration-test/src/test/java/com/acme/myproject/ModulithTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* @author Oliver Drotbohm
3838
* @author Peter Gafert
3939
*/
40-
class ModulithTest {
40+
public class ModulithTest {
4141

4242
static final DescribedPredicate<JavaClass> DEFAULT_EXCLUSIONS = Filters.withoutModules("cycleA", "cycleB", "invalid2",
4343
"invalid3", "fieldinjected");

spring-modulith-integration-test/src/test/java/com/acme/myproject/moduleD/ModuleDTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @author Oliver Drotbohm
2929
*/
3030
@NonVerifyingModuleTest
31-
class ModuleDTest {
31+
public class ModuleDTest {
3232

3333
@Autowired ConfigurableApplicationContext context;
3434

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.modulith.junit;
17+
18+
import static org.assertj.core.api.Assertions.*;
19+
20+
import java.util.Arrays;
21+
import java.util.stream.Stream;
22+
23+
import org.junit.jupiter.api.Test;
24+
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
25+
import org.springframework.modulith.junit.TestExecutionCondition.ConditionContext;
26+
import org.springframework.modulith.junit.diff.ModifiedFile;
27+
28+
import com.acme.myproject.ModulithTest;
29+
import com.acme.myproject.moduleD.ModuleDTest;
30+
31+
/**
32+
* Unit tests for {@link TestExecutionCondition}.
33+
*
34+
* @author Oliver Drotbohm
35+
*/
36+
class TestExecutionConditionUnitTests {
37+
38+
TestExecutionCondition condition = new TestExecutionCondition();
39+
40+
@Test // GH-31
41+
void enablesForSourceChangeInSameModulen() {
42+
assertEnabled(ModuleDTest.class, "moduleD/SomeConfigurationD.java");
43+
}
44+
45+
@Test // GH-31
46+
void enablesForSourceChangeInModuleDirectlyDependedOn() {
47+
assertEnabled(ModuleDTest.class, "moduleC/ServiceComponentC.java");
48+
}
49+
50+
@Test // GH-31
51+
void enablesForSourceChangeInModuleIndirectlyDependedOn() {
52+
assertEnabled(ModuleDTest.class, "moduleB/ServiceComponentB.java");
53+
}
54+
55+
@Test // GH-31
56+
void disablesForChangesInUnrelatedModule() {
57+
assertDisabled(ModuleDTest.class, "moduleB/ServiceComponentE.java");
58+
}
59+
60+
@Test // GH-31
61+
void enablesTestInRootModule() {
62+
assertEnabled(ModulithTest.class);
63+
}
64+
65+
@Test // GH-31
66+
void enablesForClasspathFileChange() {
67+
68+
var pomXml = new ModifiedFile("pom.xml");
69+
70+
assertEnabled(ModuleDTest.class, true, Stream.of(pomXml));
71+
}
72+
73+
private void assertEnabled(Class<?> type, String... files) {
74+
assertEnabled(type, true, files);
75+
}
76+
77+
private void assertDisabled(Class<?> type, String... files) {
78+
assertEnabled(type, false, files);
79+
}
80+
81+
private void assertEnabled(Class<?> type, boolean expected, String... files) {
82+
83+
var modifiedFiles = Arrays.stream(files)
84+
.map("src/main/java/com/acme/myproject/"::concat)
85+
.map(ModifiedFile::new);
86+
87+
assertEnabled(type, expected, modifiedFiles);
88+
}
89+
90+
private void assertEnabled(Class<?> type, boolean expected, Stream<ModifiedFile> files) {
91+
92+
assertThat(condition.evaluate(new ConditionContext(type, Changes.of(files))))
93+
.extracting(ConditionEvaluationResult::isDisabled)
94+
.isNotEqualTo(expected);
95+
}
96+
}

spring-modulith-junit/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

13-
<name>Spring Modulith - Test Junit</name>
13+
<name>Spring Modulith - JUnit Integration</name>
1414

1515
<artifactId>spring-modulith-junit</artifactId>
1616

@@ -22,7 +22,7 @@
2222
<dependency>
2323
<groupId>org.eclipse.jgit</groupId>
2424
<artifactId>org.eclipse.jgit</artifactId>
25-
<version>6.8.0.202311291450-r</version>
25+
<version>${jgit.version}</version>
2626
</dependency>
2727
<dependency>
2828
<groupId>org.springframework.modulith</groupId>

spring-modulith-junit/src/main/java/org/springframework/modulith/junit/Change.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)