-
Notifications
You must be signed in to change notification settings - Fork 38.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix package tangle in bean override tests
This commit fixes a package tangle between the root bean override package and its sub-packages. This was vastly improved with the introduction of `@DummyBean` but we still had a few tests that were at the wrong place.
- Loading branch information
Showing
4 changed files
with
263 additions
and
168 deletions.
There are no files selected for viewing
168 changes: 0 additions & 168 deletions
168
...pringframework/test/context/bean/override/BeanOverrideContextCustomizerEqualityTests.java
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
...rg/springframework/test/context/bean/override/BeanOverrideContextCustomizerTestUtils.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,47 @@ | ||
/* | ||
* Copyright 2002-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.test.context.bean.override; | ||
|
||
import java.util.Collections; | ||
|
||
import org.springframework.lang.Nullable; | ||
import org.springframework.test.context.ContextCustomizer; | ||
|
||
/** | ||
* Test utilities for {@link BeanOverrideContextCustomizer} that are public so | ||
* that specific bean override implementations can use them. | ||
* | ||
* @author Stephane Nicoll | ||
*/ | ||
public abstract class BeanOverrideContextCustomizerTestUtils { | ||
|
||
|
||
private static final BeanOverrideContextCustomizerFactory factory = new BeanOverrideContextCustomizerFactory(); | ||
|
||
/** | ||
* Create a {@link ContextCustomizer} for the given {@code testClass}. Return | ||
* a customizer to handle any use of {@link BeanOverride} or {@code null} if | ||
* the test class does not use them. | ||
* @param testClass a test class to introspect | ||
* @return a context customizer for bean override support, or null | ||
*/ | ||
@Nullable | ||
public static ContextCustomizer createContextCustomizer(Class<?> testClass) { | ||
return factory.createContextCustomizer(testClass, Collections.emptyList()); | ||
} | ||
|
||
} |
107 changes: 107 additions & 0 deletions
107
...amework/test/context/bean/override/convention/TestBeanContextCustomizerEqualityTests.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,107 @@ | ||
/* | ||
* Copyright 2002-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.test.context.bean.override.convention; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.test.context.ContextCustomizer; | ||
import org.springframework.test.context.bean.override.BeanOverrideContextCustomizerTestUtils; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Tests that validate the behavior of {@link TestBean} with the TCF context cache. | ||
* | ||
* @author Stephane Nicoll | ||
*/ | ||
class TestBeanContextCustomizerEqualityTests { | ||
|
||
@Test | ||
void contextCustomizerWithSameOverrideInDifferentTestClassesIsEqual() { | ||
assertThat(createContextCustomizer(Case1.class)).isEqualTo(createContextCustomizer(Case2.class)); | ||
} | ||
|
||
@Test | ||
void contextCustomizerWithDifferentMethodsIsNotEqual() { | ||
assertThat(createContextCustomizer(Case1.class)).isNotEqualTo(createContextCustomizer(Case3.class)); | ||
} | ||
|
||
@Test | ||
void contextCustomizerWithByNameVsByTypeLookupIsNotEqual() { | ||
assertThat(createContextCustomizer(Case4.class)).isNotEqualTo(createContextCustomizer(Case5.class)); | ||
} | ||
|
||
|
||
private ContextCustomizer createContextCustomizer(Class<?> testClass) { | ||
ContextCustomizer customizer = BeanOverrideContextCustomizerTestUtils.createContextCustomizer(testClass); | ||
assertThat(customizer).isNotNull(); | ||
return customizer; | ||
} | ||
|
||
interface DescriptionProvider { | ||
|
||
static String createDescription() { | ||
return "override"; | ||
} | ||
|
||
} | ||
|
||
static class Case1 implements DescriptionProvider { | ||
|
||
@TestBean(methodName = "createDescription") | ||
private String description; | ||
|
||
} | ||
|
||
static class Case2 implements DescriptionProvider { | ||
|
||
@TestBean(methodName = "createDescription") | ||
private String description; | ||
|
||
} | ||
|
||
static class Case3 implements DescriptionProvider { | ||
|
||
@TestBean(methodName = "createDescription") | ||
private String description; | ||
|
||
static String createDescription() { | ||
return "another value"; | ||
} | ||
} | ||
|
||
static class Case4 { | ||
|
||
@TestBean | ||
private String description; | ||
|
||
private static String description() { | ||
return "overridden"; | ||
} | ||
} | ||
|
||
static class Case5 { | ||
|
||
@TestBean(name = "descriptionBean") | ||
private String description; | ||
|
||
private static String description() { | ||
return "overridden"; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.