37
37
import static org .assertj .core .api .Assertions .assertThat ;
38
38
39
39
/**
40
- * Manage the lifecycle of an {@link ApplicationContext}. Such helper is best used as
41
- * a field of a test class, describing the shared configuration required for the test:
40
+ * Manage the lifecycle of an {@link ApplicationContext}. Such helper is best used as a
41
+ * field of a test class, describing the shared configuration required for the test:
42
42
*
43
43
* <pre class="code">
44
44
* public class FooAutoConfigurationTests {
48
48
*
49
49
* }</pre>
50
50
*
51
- * <p>The initialization above makes sure to register {@code FooAutoConfiguration} for all
51
+ * <p>
52
+ * The initialization above makes sure to register {@code FooAutoConfiguration} for all
52
53
* tests and set the {@code spring.foo} property to {@code bar} unless specified
53
54
* otherwise.
54
55
*
55
- * <p>Based on the configuration above, a specific test can simulate what would happen
56
- * if the user customizes a property and/or provides its own configuration:
56
+ * <p>
57
+ * Based on the configuration above, a specific test can simulate what would happen if the
58
+ * user customizes a property and/or provides its own configuration:
57
59
*
58
60
* <pre class="code">
59
61
* public class FooAutoConfigurationTests {
68
70
*
69
71
* }</pre>
70
72
*
71
- * <p>The test above includes an extra {@code UserConfig} class that is guaranteed to
72
- * be processed <strong>before</strong> any auto-configuration. Also, {@code spring.foo}
73
- * has been overwritten to {@code biz}. The {@link #load(ContextConsumer) load} method
74
- * takes a consumer that can use the context to assert its state. Upon completion, the
75
- * context is automatically closed.
73
+ * <p>
74
+ * The test above includes an extra {@code UserConfig} class that is guaranteed to be
75
+ * processed <strong>before</strong> any auto-configuration. Also, {@code spring.foo} has
76
+ * been overwritten to {@code biz}. The {@link #load(ContextConsumer) load} method takes a
77
+ * consumer that can use the context to assert its state. Upon completion, the context is
78
+ * automatically closed.
76
79
*
77
- * <p>If a failure scenario has to be tested, {@link #loadAndFail(Consumer)} can be used
80
+ * <p>
81
+ * If a failure scenario has to be tested, {@link #loadAndFail(Consumer)} can be used
78
82
* instead: it expects the startup of the context to fail and call the {@link Consumer}
79
83
* with the exception for further assertions.
80
84
*
@@ -95,10 +99,9 @@ public class ContextLoader {
95
99
private ClassLoader classLoader ;
96
100
97
101
/**
98
- * Set the specified system property prior to loading the context and restore
99
- * its previous value once the consumer has been invoked and the context closed. If
100
- * the {@code value} is {@code null} this removes any prior customization for that
101
- * key.
102
+ * Set the specified system property prior to loading the context and restore its
103
+ * previous value once the consumer has been invoked and the context closed. If the
104
+ * {@code value} is {@code null} this removes any prior customization for that key.
102
105
* @param key the system property
103
106
* @param value the value (can be null to remove any existing customization)
104
107
* @return this instance
@@ -115,10 +118,10 @@ public ContextLoader systemProperty(String key, String value) {
115
118
}
116
119
117
120
/**
118
- * Add the specified property pairs. Name -value pairs can be specified with
119
- * colon (":") or equals ("=") separators. Override matching keys that might
120
- * have been specified previously.
121
- * @param pairs The key value pairs for properties that need to be added to the
121
+ * Add the specified property pairs. Key -value pairs can be specified with colon (":")
122
+ * or equals ("=") separators. Override matching keys that might have been specified
123
+ * previously.
124
+ * @param pairs the key- value pairs for properties that need to be added to the
122
125
* environment
123
126
* @return this instance
124
127
*/
@@ -155,10 +158,9 @@ public ContextLoader autoConfig(Class<?>... autoConfigurations) {
155
158
156
159
/**
157
160
* Add the specified auto-configurations at the beginning (in that order) so that it
158
- * is applied before any other existing auto-configurations, but after any
159
- * user configuration. If {@code A} and {@code B} are specified, {@code A} will
160
- * be processed, then {@code B} and finally the rest of the existing
161
- * auto-configuration.
161
+ * is applied before any other existing auto-configurations, but after any user
162
+ * configuration. If {@code A} and {@code B} are specified, {@code A} will be
163
+ * processed, then {@code B} and finally the rest of the existing auto-configuration.
162
164
* @param autoConfigurations the auto-configuration to add
163
165
* @return this instance
164
166
*/
@@ -168,9 +170,9 @@ public ContextLoader autoConfigFirst(Class<?>... autoConfigurations) {
168
170
}
169
171
170
172
/**
171
- * Customize the {@link ClassLoader} that the {@link ApplicationContext} should
172
- * use. Customizing the {@link ClassLoader} is an effective manner to hide resources
173
- * from the classpath.
173
+ * Customize the {@link ClassLoader} that the {@link ApplicationContext} should use.
174
+ * Customizing the {@link ClassLoader} is an effective manner to hide resources from
175
+ * the classpath.
174
176
* @param classLoader the classloader to use (can be null to use the default)
175
177
* @return this instance
176
178
* @see HidePackagesClassLoader
@@ -181,9 +183,9 @@ public ContextLoader classLoader(ClassLoader classLoader) {
181
183
}
182
184
183
185
/**
184
- * Create and refresh a new {@link ApplicationContext} based on the current state
185
- * of this loader. The context is consumed by the specified {@link ContextConsumer}
186
- * and closed upon completion.
186
+ * Create and refresh a new {@link ApplicationContext} based on the current state of
187
+ * this loader. The context is consumed by the specified {@link ContextConsumer} and
188
+ * closed upon completion.
187
189
* @param consumer the consumer of the created {@link ApplicationContext}
188
190
*/
189
191
public void load (ContextConsumer consumer ) {
@@ -196,15 +198,15 @@ public void load(ContextConsumer consumer) {
196
198
throw ex ;
197
199
}
198
200
catch (Throwable ex ) {
199
- throw new IllegalStateException ("An unexpected error occurred: "
200
- + ex .getMessage (), ex );
201
+ throw new IllegalStateException (
202
+ "An unexpected error occurred: " + ex .getMessage (), ex );
201
203
}
202
204
}
203
205
}
204
206
205
207
/**
206
- * Create and refresh a new {@link ApplicationContext} based on the current state
207
- * of this loader that this expected to fail. If the context does not fail, an
208
+ * Create and refresh a new {@link ApplicationContext} based on the current state of
209
+ * this loader that this expected to fail. If the context does not fail, an
208
210
* {@link AssertionError} is thrown. Otherwise the exception is consumed by the
209
211
* specified {@link Consumer} with no expectation on the type of the exception.
210
212
* @param consumer the consumer of the failure
@@ -214,8 +216,8 @@ public void loadAndFail(Consumer<Throwable> consumer) {
214
216
}
215
217
216
218
/**
217
- * Create and refresh a new {@link ApplicationContext} based on the current state
218
- * of this loader that this expected to fail. If the context does not fail, an
219
+ * Create and refresh a new {@link ApplicationContext} based on the current state of
220
+ * this loader that this expected to fail. If the context does not fail, an
219
221
* {@link AssertionError} is thrown. If the exception does not match the specified
220
222
* {@code exceptionType}, an {@link AssertionError} is thrown as well. If the
221
223
* exception type matches, it is consumed by the specified {@link Consumer}.
@@ -246,14 +248,14 @@ private ConfigurableApplicationContext createApplicationContext() {
246
248
.applyTo (ctx );
247
249
}
248
250
if (!ObjectUtils .isEmpty (this .userConfigurations )) {
249
- ctx .register (this .userConfigurations . toArray (
250
- new Class <?>[this .userConfigurations .size ()]));
251
+ ctx .register (this .userConfigurations
252
+ . toArray ( new Class <?>[this .userConfigurations .size ()]));
251
253
}
252
254
if (!ObjectUtils .isEmpty (this .autoConfigurations )) {
253
- LinkedHashSet <Class <?>> linkedHashSet =
254
- new LinkedHashSet ( this .autoConfigurations );
255
- ctx .register (linkedHashSet . toArray (
256
- new Class <?>[this .autoConfigurations .size ()]));
255
+ LinkedHashSet <Class <?>> linkedHashSet = new LinkedHashSet <>(
256
+ this .autoConfigurations );
257
+ ctx .register (
258
+ linkedHashSet . toArray ( new Class <?>[this .autoConfigurations .size ()]));
257
259
}
258
260
return ctx ;
259
261
}
0 commit comments