diff --git a/spring-context/src/testFixtures/java/org/springframework/context/testfixture/jndi/SimpleNamingContext.java b/spring-context/src/testFixtures/java/org/springframework/context/testfixture/jndi/SimpleNamingContext.java index 7eeaea2f24..92b0e3fc4b 100644 --- a/spring-context/src/testFixtures/java/org/springframework/context/testfixture/jndi/SimpleNamingContext.java +++ b/spring-context/src/testFixtures/java/org/springframework/context/testfixture/jndi/SimpleNamingContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -126,7 +126,7 @@ public class SimpleNamingContext implements Context { if (logger.isDebugEnabled()) { logger.debug("Static JNDI lookup: [" + name + "]"); } - if ("".equals(name)) { + if (name.isEmpty()) { return new SimpleNamingContext(this.root, this.boundObjects, this.environment); } Object found = this.boundObjects.get(name); @@ -303,10 +303,10 @@ public class SimpleNamingContext implements Context { private abstract static class AbstractNamingEnumeration implements NamingEnumeration { - private Iterator iterator; + private final Iterator iterator; private AbstractNamingEnumeration(SimpleNamingContext context, String proot) throws NamingException { - if (!"".equals(proot) && !proot.endsWith("/")) { + if (!proot.isEmpty() && !proot.endsWith("/")) { proot = proot + "/"; } String root = context.root + proot; diff --git a/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContext.java b/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContext.java index f52b8191d4..14c4881c80 100644 --- a/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContext.java +++ b/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -303,7 +303,7 @@ public class SimpleNamingContext implements Context { private abstract static class AbstractNamingEnumeration implements NamingEnumeration { - private Iterator iterator; + private final Iterator iterator; private AbstractNamingEnumeration(SimpleNamingContext context, String proot) throws NamingException { if (!proot.isEmpty() && !proot.endsWith("/")) { diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java b/spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java index b2ea37b9fe..8b31ed1873 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java @@ -64,9 +64,7 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader /** * Load a Spring ApplicationContext from the supplied {@link MergedContextConfiguration}. - * *

Implementation details: - * *

    *
  • Calls {@link #validateMergedContextConfiguration(MergedContextConfiguration)} * to allow subclasses to validate the supplied configuration before proceeding.
  • @@ -98,7 +96,6 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader *
  • {@link ConfigurableApplicationContext#refresh Refreshes} the * context and registers a JVM shutdown hook for it.
  • *
- * * @return a new application context * @see org.springframework.test.context.SmartContextLoader#loadContext(MergedContextConfiguration) * @see GenericApplicationContext @@ -108,17 +105,17 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader public final ConfigurableApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception { if (logger.isDebugEnabled()) { logger.debug(String.format("Loading ApplicationContext for merged context configuration [%s].", - mergedConfig)); + mergedConfig)); } validateMergedContextConfiguration(mergedConfig); GenericApplicationContext context = createContext(); - ApplicationContext parent = mergedConfig.getParentApplicationContext(); if (parent != null) { context.setParent(parent); } + prepareContext(context); prepareContext(context, mergedConfig); customizeBeanFactory(context.getDefaultListableBeanFactory()); @@ -126,8 +123,10 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader AnnotationConfigUtils.registerAnnotationConfigProcessors(context); customizeContext(context); customizeContext(context, mergedConfig); + context.refresh(); context.registerShutdownHook(); + return context; } @@ -147,9 +146,7 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader /** * Load a Spring ApplicationContext from the supplied {@code locations}. - * *

Implementation details: - * *

    *
  • Calls {@link #createContext()} to create a {@link GenericApplicationContext} * instance.
  • @@ -168,12 +165,10 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader *
  • {@link ConfigurableApplicationContext#refresh Refreshes} the * context and registers a JVM shutdown hook for it.
  • *
- * *

Note: this method does not provide a means to set active bean definition * profiles for the loaded context. See {@link #loadContext(MergedContextConfiguration)} * and {@link AbstractContextLoader#prepareContext(ConfigurableApplicationContext, MergedContextConfiguration)} * for an alternative. - * * @return a new application context * @see org.springframework.test.context.ContextLoader#loadContext * @see GenericApplicationContext @@ -184,28 +179,30 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader public final ConfigurableApplicationContext loadContext(String... locations) throws Exception { if (logger.isDebugEnabled()) { logger.debug(String.format("Loading ApplicationContext for locations [%s].", - StringUtils.arrayToCommaDelimitedString(locations))); + StringUtils.arrayToCommaDelimitedString(locations))); } + GenericApplicationContext context = createContext(); + prepareContext(context); customizeBeanFactory(context.getDefaultListableBeanFactory()); createBeanDefinitionReader(context).loadBeanDefinitions(locations); AnnotationConfigUtils.registerAnnotationConfigProcessors(context); customizeContext(context); + context.refresh(); context.registerShutdownHook(); + return context; } /** * Factory method for creating the {@link GenericApplicationContext} used by * this {@code ContextLoader}. - * *

The default implementation creates a {@code GenericApplicationContext} * using the default constructor. This method may be overridden in subclasses * — for example, to create a {@code GenericApplicationContext} with * a custom {@link DefaultListableBeanFactory} implementation. - * * @return a newly instantiated {@code GenericApplicationContext} * @since 5.2.9 */ @@ -216,10 +213,8 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader /** * Prepare the {@link GenericApplicationContext} created by this {@code ContextLoader}. * Called before bean definitions are read. - * *

The default implementation is empty. Can be overridden in subclasses to * customize {@code GenericApplicationContext}'s standard settings. - * * @param context the context that should be prepared * @since 2.5 * @see #loadContext(MergedContextConfiguration) @@ -235,10 +230,8 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader /** * Customize the internal bean factory of the ApplicationContext created by * this {@code ContextLoader}. - * *

The default implementation is empty but can be overridden in subclasses * to customize {@code DefaultListableBeanFactory}'s standard settings. - * * @param beanFactory the bean factory created by this {@code ContextLoader} * @since 2.5 * @see #loadContext(MergedContextConfiguration) @@ -254,18 +247,15 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader /** * Load bean definitions into the supplied {@link GenericApplicationContext context} * from the locations or classes in the supplied {@code MergedContextConfiguration}. - * *

The default implementation delegates to the {@link BeanDefinitionReader} * returned by {@link #createBeanDefinitionReader(GenericApplicationContext)} to * {@link BeanDefinitionReader#loadBeanDefinitions(String) load} the * bean definitions. - * *

Subclasses must provide an appropriate implementation of * {@link #createBeanDefinitionReader(GenericApplicationContext)}. Alternatively subclasses * may provide a no-op implementation of {@code createBeanDefinitionReader()} * and override this method to provide a custom strategy for loading or * registering bean definitions. - * * @param context the context into which the bean definitions should be loaded * @param mergedConfig the merged context configuration * @since 3.1 @@ -278,7 +268,6 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader /** * Factory method for creating a new {@link BeanDefinitionReader} for loading * bean definitions into the supplied {@link GenericApplicationContext context}. - * * @param context the context for which the {@code BeanDefinitionReader} * should be created * @return a {@code BeanDefinitionReader} for the supplied context @@ -293,10 +282,8 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader * Customize the {@link GenericApplicationContext} created by this * {@code ContextLoader} after bean definitions have been * loaded into the context but before the context is refreshed. - * *

The default implementation is empty but can be overridden in subclasses * to customize the application context. - * * @param context the newly created application context * @since 2.5 * @see #loadContext(MergedContextConfiguration) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ToStringVisitor.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ToStringVisitor.java index 52a4f33256..dcfb74e569 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ToStringVisitor.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ToStringVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -76,7 +76,7 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi } private void indent() { - for (int i=0; i < this.indent; i++) { + for (int i = 0; i < this.indent; i++) { this.builder.append(' '); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ToStringVisitor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ToStringVisitor.java index 5e5fb3d3fe..31e8c4ed3e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ToStringVisitor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ToStringVisitor.java @@ -38,6 +38,7 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi // RouterFunctions.Visitor + @Override public void startNested(RequestPredicate predicate) { indent(); @@ -74,11 +75,12 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi } private void indent() { - for (int i=0; i < this.indent; i++) { + for (int i = 0; i < this.indent; i++) { this.builder.append(' '); } } + // RequestPredicates.Visitor @Override @@ -156,6 +158,7 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi public void unknown(RequestPredicate predicate) { this.builder.append(predicate); } + @Override public String toString() { String result = this.builder.toString(); @@ -164,4 +167,5 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi } return result; } + }