4343 */
4444abstract class BootstrapUtils {
4545
46- private static final String DEFAULT_BOOTSTRAP_CONTEXT_CLASS_NAME = "org.springframework.test.context.support.DefaultBootstrapContext" ;
46+ private static final String DEFAULT_BOOTSTRAP_CONTEXT_CLASS_NAME =
47+ "org.springframework.test.context.support.DefaultBootstrapContext" ;
4748
48- private static final String DEFAULT_CACHE_AWARE_CONTEXT_LOADER_DELEGATE_CLASS_NAME = "org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate" ;
49+ private static final String DEFAULT_CACHE_AWARE_CONTEXT_LOADER_DELEGATE_CLASS_NAME =
50+ "org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate" ;
4951
50- private static final String DEFAULT_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME = "org.springframework.test.context.support.DefaultTestContextBootstrapper" ;
52+ private static final String DEFAULT_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME =
53+ "org.springframework.test.context.support.DefaultTestContextBootstrapper" ;
5154
52- private static final String DEFAULT_WEB_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME = "org.springframework.test.context.web.WebTestContextBootstrapper" ;
55+ private static final String DEFAULT_WEB_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME =
56+ "org.springframework.test.context.web.WebTestContextBootstrapper" ;
5357
54- private static final String WEB_APP_CONFIGURATION_ANNOTATION_CLASS_NAME = "org.springframework.test.context.web.WebAppConfiguration" ;
58+ private static final String WEB_APP_CONFIGURATION_ANNOTATION_CLASS_NAME =
59+ "org.springframework.test.context.web.WebAppConfiguration" ;
5560
5661 private static final Log logger = LogFactory .getLog (BootstrapUtils .class );
5762
5863
59- private BootstrapUtils () {
60- /* no-op */
61- }
62-
6364 /**
6465 * Create the {@code BootstrapContext} for the specified {@linkplain Class test class}.
65- *
6666 * <p>Uses reflection to create a {@link org.springframework.test.context.support.DefaultBootstrapContext}
6767 * that uses a {@link org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate}.
68- *
6968 * @param testClass the test class for which the bootstrap context should be created
7069 * @return a new {@code BootstrapContext}; never {@code null}
7170 */
7271 @ SuppressWarnings ("unchecked" )
7372 static BootstrapContext createBootstrapContext (Class <?> testClass ) {
7473 CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = createCacheAwareContextLoaderDelegate ();
75-
7674 Class <? extends BootstrapContext > clazz = null ;
7775 try {
78- clazz = (Class <? extends BootstrapContext >) ClassUtils .forName (DEFAULT_BOOTSTRAP_CONTEXT_CLASS_NAME ,
79- BootstrapUtils .class .getClassLoader ());
80-
81- Constructor <? extends BootstrapContext > constructor = clazz .getConstructor (Class .class ,
82- CacheAwareContextLoaderDelegate .class );
83-
76+ clazz = (Class <? extends BootstrapContext >) ClassUtils .forName (
77+ DEFAULT_BOOTSTRAP_CONTEXT_CLASS_NAME , BootstrapUtils .class .getClassLoader ());
78+ Constructor <? extends BootstrapContext > constructor = clazz .getConstructor (
79+ Class .class , CacheAwareContextLoaderDelegate .class );
8480 if (logger .isDebugEnabled ()) {
8581 logger .debug (String .format ("Instantiating BootstrapContext using constructor [%s]" , constructor ));
8682 }
8783 return instantiateClass (constructor , testClass , cacheAwareContextLoaderDelegate );
8884 }
89- catch (Throwable t ) {
90- throw new IllegalStateException ("Could not load BootstrapContext [" + clazz + "]" , t );
85+ catch (Throwable ex ) {
86+ throw new IllegalStateException ("Could not load BootstrapContext [" + clazz + "]" , ex );
9187 }
9288 }
9389
@@ -104,16 +100,15 @@ private static CacheAwareContextLoaderDelegate createCacheAwareContextLoaderDele
104100 }
105101 return instantiateClass (clazz , CacheAwareContextLoaderDelegate .class );
106102 }
107- catch (Throwable t ) {
108- throw new IllegalStateException ("Could not load CacheAwareContextLoaderDelegate [" + clazz + "]" , t );
103+ catch (Throwable ex ) {
104+ throw new IllegalStateException ("Could not load CacheAwareContextLoaderDelegate [" + clazz + "]" , ex );
109105 }
110106 }
111107
112108 /**
113109 * Resolve the {@link TestContextBootstrapper} type for the test class in the
114110 * supplied {@link BootstrapContext}, instantiate it, and provide it a reference
115111 * to the {@link BootstrapContext}.
116- *
117112 * <p>If the {@link BootstrapWith @BootstrapWith} annotation is present on
118113 * the test class, either directly or as a meta-annotation, then its
119114 * {@link BootstrapWith#value value} will be used as the bootstrapper type.
@@ -123,7 +118,6 @@ private static CacheAwareContextLoaderDelegate createCacheAwareContextLoaderDele
123118 * {@link org.springframework.test.context.web.WebTestContextBootstrapper
124119 * WebTestContextBootstrapper} will be used, depending on the presence of
125120 * {@link org.springframework.test.context.web.WebAppConfiguration @WebAppConfiguration}.
126- *
127121 * @param bootstrapContext the bootstrap context to use
128122 * @return a fully configured {@code TestContextBootstrapper}
129123 */
@@ -138,36 +132,36 @@ static TestContextBootstrapper resolveTestContextBootstrapper(BootstrapContext b
138132 }
139133 if (logger .isDebugEnabled ()) {
140134 logger .debug (String .format ("Instantiating TestContextBootstrapper for test class [%s] from class [%s]" ,
141- testClass .getName (), clazz .getName ()));
135+ testClass .getName (), clazz .getName ()));
142136 }
143-
144137 TestContextBootstrapper testContextBootstrapper = instantiateClass (clazz , TestContextBootstrapper .class );
145138 testContextBootstrapper .setBootstrapContext (bootstrapContext );
146-
147139 return testContextBootstrapper ;
148140 }
149141 catch (Throwable ex ) {
150142 if (ex instanceof IllegalStateException ) {
151143 throw (IllegalStateException ) ex ;
152144 }
153- throw new IllegalStateException ("Could not load TestContextBootstrapper [" + clazz
154- + "]. Specify @BootstrapWith's 'value' attribute "
155- + "or make the default bootstrapper class available." , ex );
145+ throw new IllegalStateException ("Could not load TestContextBootstrapper [" + clazz +
146+ "]. Specify @BootstrapWith's 'value' attribute or make the default bootstrapper class available." ,
147+ ex );
156148 }
157149 }
158150
159151 /**
160152 * @since 4.3
161153 */
162154 private static Class <?> resolveExplicitTestContextBootstrapper (Class <?> testClass ) {
163- MultiValueMap <String , Object > attributesMultiMap = AnnotatedElementUtils . getAllAnnotationAttributes (
164- testClass , BootstrapWith .class .getName ());
165- List <Object > values = (attributesMultiMap == null ? null : attributesMultiMap .get (AnnotationUtils .VALUE ));
155+ MultiValueMap <String , Object > attributesMultiMap =
156+ AnnotatedElementUtils . getAllAnnotationAttributes ( testClass , BootstrapWith .class .getName ());
157+ List <Object > values = (attributesMultiMap != null ? attributesMultiMap .get (AnnotationUtils .VALUE ) : null );
166158 if (values == null ) {
167159 return null ;
168160 }
169- Assert .state (values .size () == 1 , String .format ("Configuration error: found multiple declarations of "
170- + "@BootstrapWith on test class [%s] with values %s" , testClass .getName (), values ));
161+ if (values .size () != 1 ) {
162+ throw new IllegalStateException (String .format ("Configuration error: found multiple declarations of " +
163+ "@BootstrapWith on test class [%s] with values %s" , testClass .getName (), values ));
164+ }
171165 return (Class <?>) values .get (0 );
172166 }
173167
0 commit comments