25
25
import org .apache .commons .logging .LogFactory ;
26
26
27
27
import org .springframework .beans .BeanUtils ;
28
+ import org .springframework .core .log .LogMessage ;
28
29
import org .springframework .lang .Nullable ;
29
30
import org .springframework .test .context .TestContextAnnotationUtils .AnnotationDescriptor ;
30
31
import org .springframework .util .ClassUtils ;
@@ -74,36 +75,33 @@ public abstract class BootstrapUtils {
74
75
@ SuppressWarnings ("unchecked" )
75
76
static BootstrapContext createBootstrapContext (Class <?> testClass ) {
76
77
CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = createCacheAwareContextLoaderDelegate ();
78
+ String className = DEFAULT_BOOTSTRAP_CONTEXT_CLASS_NAME ;
77
79
Class <? extends BootstrapContext > clazz = null ;
78
80
try {
79
- clazz = (Class <? extends BootstrapContext >) ClassUtils .forName (
80
- DEFAULT_BOOTSTRAP_CONTEXT_CLASS_NAME , BootstrapUtils .class .getClassLoader ());
81
- Constructor <? extends BootstrapContext > constructor = clazz .getConstructor (
82
- Class .class , CacheAwareContextLoaderDelegate .class );
83
- if (logger .isDebugEnabled ()) {
84
- logger .debug (String .format ("Instantiating BootstrapContext using constructor [%s]" , constructor ));
85
- }
81
+ clazz = (Class <? extends BootstrapContext >)
82
+ ClassUtils .forName (className , BootstrapUtils .class .getClassLoader ());
83
+ Constructor <? extends BootstrapContext > constructor =
84
+ clazz .getConstructor (Class .class , CacheAwareContextLoaderDelegate .class );
85
+ logger .debug (LogMessage .format ("Instantiating BootstrapContext using constructor [%s]" , constructor ));
86
86
return BeanUtils .instantiateClass (constructor , testClass , cacheAwareContextLoaderDelegate );
87
87
}
88
88
catch (Throwable ex ) {
89
- throw new IllegalStateException ("Could not load BootstrapContext [" + clazz + "]" , ex );
89
+ throw new IllegalStateException ("Could not load BootstrapContext [%s]" . formatted ( className ) , ex );
90
90
}
91
91
}
92
92
93
93
@ SuppressWarnings ("unchecked" )
94
94
private static CacheAwareContextLoaderDelegate createCacheAwareContextLoaderDelegate () {
95
+ String className = DEFAULT_CACHE_AWARE_CONTEXT_LOADER_DELEGATE_CLASS_NAME ;
95
96
Class <? extends CacheAwareContextLoaderDelegate > clazz = null ;
96
97
try {
97
- clazz = (Class <? extends CacheAwareContextLoaderDelegate >) ClassUtils .forName (
98
- DEFAULT_CACHE_AWARE_CONTEXT_LOADER_DELEGATE_CLASS_NAME , BootstrapUtils .class .getClassLoader ());
99
- if (logger .isDebugEnabled ()) {
100
- logger .debug (String .format ("Instantiating CacheAwareContextLoaderDelegate from class [%s]" ,
101
- clazz .getName ()));
102
- }
98
+ clazz = (Class <? extends CacheAwareContextLoaderDelegate >)
99
+ ClassUtils .forName (className , BootstrapUtils .class .getClassLoader ());
100
+ logger .debug (LogMessage .format ("Instantiating CacheAwareContextLoaderDelegate from class [%s]" , className ));
103
101
return BeanUtils .instantiateClass (clazz , CacheAwareContextLoaderDelegate .class );
104
102
}
105
103
catch (Throwable ex ) {
106
- throw new IllegalStateException ("Could not load CacheAwareContextLoaderDelegate [" + clazz + "]" , ex );
104
+ throw new IllegalStateException ("Could not load CacheAwareContextLoaderDelegate [%s]" . formatted ( className ) , ex );
107
105
}
108
106
}
109
107
@@ -153,10 +151,8 @@ static TestContextBootstrapper resolveTestContextBootstrapper(BootstrapContext b
153
151
if (clazz == null ) {
154
152
clazz = resolveDefaultTestContextBootstrapper (testClass );
155
153
}
156
- if (logger .isDebugEnabled ()) {
157
- logger .debug (String .format ("Instantiating TestContextBootstrapper for test class [%s] from class [%s]" ,
158
- testClass .getName (), clazz .getName ()));
159
- }
154
+ logger .debug (LogMessage .format ("Instantiating TestContextBootstrapper for test class [%s] from class [%s]" ,
155
+ testClass .getName (), clazz .getName ()));
160
156
TestContextBootstrapper testContextBootstrapper =
161
157
BeanUtils .instantiateClass (clazz , TestContextBootstrapper .class );
162
158
testContextBootstrapper .setBootstrapContext (bootstrapContext );
@@ -166,9 +162,9 @@ static TestContextBootstrapper resolveTestContextBootstrapper(BootstrapContext b
166
162
throw ex ;
167
163
}
168
164
catch (Throwable ex ) {
169
- throw new IllegalStateException ("Could not load TestContextBootstrapper [" + clazz +
170
- " ]. Specify @BootstrapWith's 'value' attribute or make the default bootstrapper class available." ,
171
- ex );
165
+ throw new IllegalStateException ("""
166
+ Could not load TestContextBootstrapper [%s ]. Specify @BootstrapWith's 'value' \
167
+ attribute or make the default bootstrapper class available.""" . formatted ( clazz ), ex );
172
168
}
173
169
}
174
170
0 commit comments