Skip to content

Commit 06d47fb

Browse files
committed
GH-1050 - ModuleContextCustomizer are now considered equal if their backing execution is.
1 parent 34ff544 commit 06d47fb

File tree

5 files changed

+68
-7
lines changed

5 files changed

+68
-7
lines changed

spring-modulith-test/src/main/java/org/springframework/modulith/test/ModuleContextCustomizerFactory.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,9 @@ static class ModuleContextCustomizer implements ContextCustomizer {
6363
private static final Logger LOGGER = LoggerFactory.getLogger(ModuleContextCustomizer.class);
6464

6565
private final Supplier<ModuleTestExecution> execution;
66-
private final Class<?> source;
6766

6867
ModuleContextCustomizer(Class<?> testClass) {
69-
7068
this.execution = ModuleTestExecution.of(testClass);
71-
this.source = testClass;
7269
}
7370

7471
/*
@@ -166,6 +163,7 @@ private static void logModules(ModuleTestExecution execution) {
166163
*/
167164
@Override
168165
public boolean equals(Object obj) {
166+
169167
if (this == obj) {
170168
return true;
171169
}
@@ -174,7 +172,7 @@ public boolean equals(Object obj) {
174172
return false;
175173
}
176174

177-
return Objects.equals(this.source, that.source);
175+
return Objects.equals(this.execution.get(), that.execution.get());
178176
}
179177

180178
/*
@@ -183,7 +181,7 @@ public boolean equals(Object obj) {
183181
*/
184182
@Override
185183
public int hashCode() {
186-
return Objects.hashCode(source);
184+
return Objects.hashCode(execution.get());
187185
}
188186

189187
private static void logHeadline(String headline) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2025 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 example.module;
17+
18+
import org.springframework.modulith.test.ApplicationModuleTest;
19+
20+
/**
21+
* @author Oliver Drotbohm
22+
*/
23+
@ApplicationModuleTest
24+
public class SampleTestA {
25+
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2025 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 example.module;
17+
18+
import org.springframework.modulith.test.ApplicationModuleTest;
19+
20+
/**
21+
* @author Oliver Drotbohm
22+
*/
23+
@ApplicationModuleTest
24+
public class SampleTestB {}

spring-modulith-test/src/test/java/org/springframework/modulith/test/ModuleContextCustomizerUnitTests.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static org.assertj.core.api.Assertions.*;
1919

2020
import example.module.SampleTestA;
21+
import example.module.SampleTestB;
2122

2223
import org.junit.jupiter.api.Test;
2324
import org.springframework.modulith.core.ApplicationModule;
@@ -34,8 +35,8 @@ class ModuleContextCustomizerUnitTests {
3435
@Test
3536
void instancesForSameTargetTypeAreEqual() {
3637

37-
var left = new ModuleContextCustomizer(Object.class);
38-
var right = new ModuleContextCustomizer(Object.class);
38+
var left = new ModuleContextCustomizer(SampleTestA.class);
39+
var right = new ModuleContextCustomizer(SampleTestA.class);
3940

4041
assertThat(left).isEqualTo(right);
4142
assertThat(right).isEqualTo(left);
@@ -53,4 +54,15 @@ void usesTestClassIfConfigured() {
5354
.extracting(ApplicationModuleIdentifier::toString)
5455
.isEqualTo("module");
5556
}
57+
58+
@Test // GH-1050
59+
void instancesWithSameModuleSetupAreConsideredEqual() {
60+
61+
var left = new ModuleContextCustomizer(SampleTestA.class);
62+
var right = new ModuleContextCustomizer(SampleTestB.class);
63+
64+
assertThat(left).isEqualTo(right);
65+
assertThat(right).isEqualTo(left);
66+
assertThat(left).hasSameHashCodeAs(right);
67+
}
5668
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.springframework.modulith.core.ApplicationModulesFactory=org.springframework.modulith.test.TestApplicationModules.Factory

0 commit comments

Comments
 (0)