-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-757 - Fix test context cache key contributions.
Both ModuleContextCustomizer and ModuleTypeExcludeFilter contribute to the calculation of the context configuration which the Spring Test Context Framework uses to decide whether it's necessary to create new ApplicationContext instances. Both of them previously used a Supplier<ModuleTestExecution> to calculate equals(…) and hashCode() which -- by definition -- does not result in the same result even when created with identical input. We now rather use the source class instance eventually backing the ModuleTestExecution, as that is the internal cache key in turn.
- Loading branch information
1 parent
0ba371f
commit 1dbce34
Showing
4 changed files
with
104 additions
and
17 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
40 changes: 40 additions & 0 deletions
40
...est/src/test/java/org/springframework/modulith/test/ModuleContextCustomizerUnitTests.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,40 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.modulith.test; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.modulith.test.ModuleContextCustomizerFactory.ModuleContextCustomizer; | ||
|
||
/** | ||
* Unit tests for {@link ModuleTypeExcludeFilter}. | ||
* | ||
* @author Oliver Drotbohm | ||
*/ | ||
class ModuleContextCustomizerUnitTests { | ||
|
||
@Test | ||
void instancesForSameTargetTypeAreEqual() { | ||
|
||
var left = new ModuleContextCustomizer(Object.class); | ||
var right = new ModuleContextCustomizer(Object.class); | ||
|
||
assertThat(left).isEqualTo(right); | ||
assertThat(right).isEqualTo(left); | ||
assertThat(left).hasSameHashCodeAs(right); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...est/src/test/java/org/springframework/modulith/test/ModuleTypeExcludeFilterUnitTests.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,39 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.modulith.test; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Unit tests for {@link ModuleTypeExcludeFilter}. | ||
* | ||
* @author Oliver Drotbohm | ||
*/ | ||
class ModuleTypeExcludeFilterUnitTests { | ||
|
||
@Test | ||
void instancesForSameTargetTypeAreEqual() { | ||
|
||
var left = new ModuleTypeExcludeFilter(Object.class); | ||
var right = new ModuleTypeExcludeFilter(Object.class); | ||
|
||
assertThat(left).isEqualTo(right); | ||
assertThat(right).isEqualTo(left); | ||
assertThat(left).hasSameHashCodeAs(right); | ||
} | ||
} |