Skip to content

Commit b0c7d15

Browse files
committed
Polishing
1 parent 32df079 commit b0c7d15

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

spring-core/src/main/java/org/springframework/util/StringUtils.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public abstract class StringUtils {
8080

8181
private static final String CURRENT_PATH = ".";
8282

83-
private static final char EXTENSION_SEPARATOR = '.';
83+
private static final char DOT_CHAR = '.';
8484

8585
private static final int DEFAULT_TRUNCATION_THRESHOLD = 100;
8686

@@ -538,7 +538,7 @@ public static Object quoteIfString(@Nullable Object obj) {
538538
* @param qualifiedName the qualified name
539539
*/
540540
public static String unqualify(String qualifiedName) {
541-
return unqualify(qualifiedName, '.');
541+
return unqualify(qualifiedName, DOT_CHAR);
542542
}
543543

544544
/**
@@ -641,7 +641,7 @@ public static String getFilenameExtension(@Nullable String path) {
641641
return null;
642642
}
643643

644-
int extIndex = path.lastIndexOf(EXTENSION_SEPARATOR);
644+
int extIndex = path.lastIndexOf(DOT_CHAR);
645645
if (extIndex == -1) {
646646
return null;
647647
}
@@ -661,7 +661,7 @@ public static String getFilenameExtension(@Nullable String path) {
661661
* @return the path with stripped filename extension
662662
*/
663663
public static String stripFilenameExtension(String path) {
664-
int extIndex = path.lastIndexOf(EXTENSION_SEPARATOR);
664+
int extIndex = path.lastIndexOf(DOT_CHAR);
665665
if (extIndex == -1) {
666666
return path;
667667
}
@@ -724,7 +724,7 @@ public static String cleanPath(String path) {
724724
String pathToUse = normalizedPath;
725725

726726
// Shortcut if there is no work to do
727-
if (pathToUse.indexOf(EXTENSION_SEPARATOR) == -1) {
727+
if (pathToUse.indexOf(DOT_CHAR) == -1) {
728728
return pathToUse;
729729
}
730730

spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessor.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private void replaceDefinition(ConfigurableListableBeanFactory beanFactory, Over
109109

110110
if (!(beanFactory instanceof BeanDefinitionRegistry registry)) {
111111
throw new IllegalStateException("Cannot process bean override with a BeanFactory " +
112-
"that doesn't implement BeanDefinitionRegistry: " + beanFactory.getClass());
112+
"that doesn't implement BeanDefinitionRegistry: " + beanFactory.getClass().getName());
113113
}
114114

115115
// The following is a "pseudo" bean definition which MUST NOT be used to
@@ -176,10 +176,12 @@ private void wrapBean(ConfigurableListableBeanFactory beanFactory, OverrideMetad
176176
int candidateCount = candidateNames.size();
177177
if (candidateCount != 1) {
178178
Field field = overrideMetadata.getField();
179-
throw new IllegalStateException("Unable to select a bean to override by wrapping: found " +
180-
candidateCount + " bean instances of type " + overrideMetadata.getBeanType() +
181-
" (as required by annotated field '" + field.getDeclaringClass().getSimpleName() +
182-
"." + field.getName() + "')" + (candidateCount > 0 ? ": " + candidateNames : ""));
179+
throw new IllegalStateException("""
180+
Unable to select a bean to override by wrapping: found %d bean instances of type %s \
181+
(as required by annotated field '%s.%s')%s"""
182+
.formatted(candidateCount, overrideMetadata.getBeanType(),
183+
field.getDeclaringClass().getSimpleName(), field.getName(),
184+
(candidateCount > 0 ? ": " + candidateNames : "")));
183185
}
184186
beanName = BeanFactoryUtils.transformedBeanName(candidateNames.iterator().next());
185187
}

spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class BeanOverrideContextCustomizer implements ContextCustomizer {
5858
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
5959
if (!(context instanceof BeanDefinitionRegistry registry)) {
6060
throw new IllegalStateException("Cannot process bean overrides with an ApplicationContext " +
61-
"that doesn't implement BeanDefinitionRegistry: " + context.getClass());
61+
"that doesn't implement BeanDefinitionRegistry: " + context.getClass().getName());
6262
}
6363
registerInfrastructure(registry);
6464
}

spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideRegistrar.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class BeanOverrideRegistrar implements BeanFactoryAware {
5252
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
5353
if (!(beanFactory instanceof ConfigurableBeanFactory cbf)) {
5454
throw new IllegalStateException("Cannot process bean override with a BeanFactory " +
55-
"that doesn't implement ConfigurableBeanFactory: " + beanFactory.getClass());
55+
"that doesn't implement ConfigurableBeanFactory: " + beanFactory.getClass().getName());
5656
}
5757
this.beanFactory = cbf;
5858
}

spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideTestExecutionListener.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,28 @@ public void prepareTestInstance(TestContext testContext) throws Exception {
4949

5050
@Override
5151
public void beforeTestMethod(TestContext testContext) throws Exception {
52-
reinjectFieldsIfConfigured(testContext);
52+
reinjectFieldsIfNecessary(testContext);
5353
}
5454

5555
/**
5656
* Process the test instance and make sure that fields flagged for bean
57-
* overriding are processed.
58-
* <p>Each field's value will be updated with the overridden bean instance.
57+
* overriding are injected with the overridden bean instance.
5958
*/
6059
protected void injectFields(TestContext testContext) {
61-
postProcessFields(testContext, (testMetadata, overrideRegistrar) -> overrideRegistrar.inject(
62-
testMetadata.testInstance, testMetadata.overrideMetadata));
60+
postProcessFields(testContext, (testMetadata, registrar) ->
61+
registrar.inject(testMetadata.testInstance, testMetadata.overrideMetadata));
6362
}
6463

6564
/**
6665
* Process the test instance and make sure that fields flagged for bean
67-
* overriding are processed.
66+
* overriding are injected with the overridden bean instance, if necessary.
6867
* <p>If a fresh instance is required, the field is nulled out and then
6968
* re-injected with the overridden bean instance.
7069
* <p>This method does nothing if the
7170
* {@link DependencyInjectionTestExecutionListener#REINJECT_DEPENDENCIES_ATTRIBUTE}
72-
* attribute is not present in the {@code TestContext}.
71+
* attribute is not present in the {@code TestContext} with a value of {@link Boolean#TRUE}.
7372
*/
74-
protected void reinjectFieldsIfConfigured(TestContext testContext) throws Exception {
73+
protected void reinjectFieldsIfNecessary(TestContext testContext) throws Exception {
7574
if (Boolean.TRUE.equals(
7675
testContext.getAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE))) {
7776

0 commit comments

Comments
 (0)