File tree Expand file tree Collapse file tree 5 files changed +68
-7
lines changed
main/java/org/springframework/modulith/test
org/springframework/modulith/test Expand file tree Collapse file tree 5 files changed +68
-7
lines changed Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 {}
Original file line number Diff line number Diff line change 1818import static org .assertj .core .api .Assertions .*;
1919
2020import example .module .SampleTestA ;
21+ import example .module .SampleTestB ;
2122
2223import org .junit .jupiter .api .Test ;
2324import 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}
Original file line number Diff line number Diff line change 1+ org.springframework.modulith.core.ApplicationModulesFactory=org.springframework.modulith.test.TestApplicationModules.Factory
You can’t perform that action at this time.
0 commit comments