Skip to content

Commit eeeab27

Browse files
committed
Polishing
(cherry picked from commit 35e247a)
1 parent 2a4ee07 commit eeeab27

File tree

5 files changed

+48
-48
lines changed

5 files changed

+48
-48
lines changed

spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void purgeExpiredRegistries() {
174174

175175
@Override
176176
public String toString() {
177-
return "local=[" + this.localRegistry + "], remote=" + this.remoteRegistries + "]";
177+
return "local=[" + this.localRegistry + "], remote=" + this.remoteRegistries;
178178
}
179179

180180

@@ -260,7 +260,6 @@ public String toString() {
260260
/**
261261
* SimpUser that can be (de)serialized and broadcast to other servers.
262262
*/
263-
@SuppressWarnings("unused")
264263
private static class TransferSimpUser implements SimpUser {
265264

266265
private String name;
@@ -274,6 +273,7 @@ private static class TransferSimpUser implements SimpUser {
274273
/**
275274
* Default constructor for JSON deserialization.
276275
*/
276+
@SuppressWarnings("unused")
277277
public TransferSimpUser() {
278278
this.sessions = new HashSet<>(1);
279279
}
@@ -368,7 +368,6 @@ public String toString() {
368368
/**
369369
* SimpSession that can be (de)serialized and broadcast to other servers.
370370
*/
371-
@SuppressWarnings("unused")
372371
private static class TransferSimpSession implements SimpSession {
373372

374373
private String id;
@@ -380,6 +379,7 @@ private static class TransferSimpSession implements SimpSession {
380379
/**
381380
* Default constructor for JSON deserialization.
382381
*/
382+
@SuppressWarnings("unused")
383383
public TransferSimpSession() {
384384
this.subscriptions = new HashSet<>(4);
385385
}

spring-test/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ public void afterTestMethod(TestContext testContext) throws Exception {
127127
private void executeSqlScripts(TestContext testContext, ExecutionPhase executionPhase) throws Exception {
128128
boolean classLevel = false;
129129

130-
Set<Sql> sqlAnnotations = AnnotatedElementUtils.getMergedRepeatableAnnotations(testContext.getTestMethod(), Sql.class,
131-
SqlGroup.class);
130+
Set<Sql> sqlAnnotations = AnnotatedElementUtils.getMergedRepeatableAnnotations(
131+
testContext.getTestMethod(), Sql.class, SqlGroup.class);
132132
if (sqlAnnotations.isEmpty()) {
133-
sqlAnnotations = AnnotatedElementUtils.getMergedRepeatableAnnotations(testContext.getTestClass(), Sql.class,
134-
SqlGroup.class);
133+
sqlAnnotations = AnnotatedElementUtils.getMergedRepeatableAnnotations(
134+
testContext.getTestClass(), Sql.class, SqlGroup.class);
135135
if (!sqlAnnotations.isEmpty()) {
136136
classLevel = true;
137137
}
@@ -145,26 +145,24 @@ private void executeSqlScripts(TestContext testContext, ExecutionPhase execution
145145
/**
146146
* Execute the SQL scripts configured via the supplied {@link Sql @Sql}
147147
* annotation for the given {@link ExecutionPhase} and {@link TestContext}.
148-
*
149148
* <p>Special care must be taken in order to properly support the configured
150149
* {@link SqlConfig#transactionMode}.
151-
*
152150
* @param sql the {@code @Sql} annotation to parse
153151
* @param executionPhase the current execution phase
154152
* @param testContext the current {@code TestContext}
155-
* @param classLevel {@code true} if {@link Sql @Sql} was declared at the
156-
* class level
153+
* @param classLevel {@code true} if {@link Sql @Sql} was declared at the class level
157154
*/
158155
private void executeSqlScripts(Sql sql, ExecutionPhase executionPhase, TestContext testContext, boolean classLevel)
159156
throws Exception {
157+
160158
if (executionPhase != sql.executionPhase()) {
161159
return;
162160
}
163161

164162
MergedSqlConfig mergedSqlConfig = new MergedSqlConfig(sql.config(), testContext.getTestClass());
165163
if (logger.isDebugEnabled()) {
166-
logger.debug(String.format("Processing %s for execution phase [%s] and test context %s.", mergedSqlConfig,
167-
executionPhase, testContext));
164+
logger.debug(String.format("Processing %s for execution phase [%s] and test context %s.",
165+
mergedSqlConfig, executionPhase, testContext));
168166
}
169167

170168
final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
@@ -179,15 +177,13 @@ private void executeSqlScripts(Sql sql, ExecutionPhase executionPhase, TestConte
179177
String[] scripts = getScripts(sql, testContext, classLevel);
180178
scripts = TestContextResourceUtils.convertToClasspathResourcePaths(testContext.getTestClass(), scripts);
181179
List<Resource> scriptResources = TestContextResourceUtils.convertToResourceList(
182-
testContext.getApplicationContext(), scripts);
183-
184-
for (String statement : sql.statements()) {
185-
if (StringUtils.hasText(statement)) {
186-
statement = statement.trim();
187-
scriptResources.add(new ByteArrayResource(statement.getBytes(), "from inlined SQL statement: " + statement));
180+
testContext.getApplicationContext(), scripts);
181+
for (String stmt : sql.statements()) {
182+
if (StringUtils.hasText(stmt)) {
183+
stmt = stmt.trim();
184+
scriptResources.add(new ByteArrayResource(stmt.getBytes(), "from inlined SQL statement: " + stmt));
188185
}
189186
}
190-
191187
populator.setScripts(scriptResources.toArray(new Resource[scriptResources.size()]));
192188
if (logger.isDebugEnabled()) {
193189
logger.debug("Executing SQL scripts: " + ObjectUtils.nullSafeToString(scriptResources));
@@ -196,47 +192,39 @@ private void executeSqlScripts(Sql sql, ExecutionPhase executionPhase, TestConte
196192
String dsName = mergedSqlConfig.getDataSource();
197193
String tmName = mergedSqlConfig.getTransactionManager();
198194
DataSource dataSource = TestContextTransactionUtils.retrieveDataSource(testContext, dsName);
199-
final PlatformTransactionManager transactionManager = TestContextTransactionUtils.retrieveTransactionManager(
200-
testContext, tmName);
201-
final boolean newTxRequired = mergedSqlConfig.getTransactionMode() == TransactionMode.ISOLATED;
195+
PlatformTransactionManager txMgr = TestContextTransactionUtils.retrieveTransactionManager(testContext, tmName);
196+
boolean newTxRequired = (mergedSqlConfig.getTransactionMode() == TransactionMode.ISOLATED);
202197

203-
if (transactionManager == null) {
198+
if (txMgr == null) {
204199
Assert.state(!newTxRequired, () -> String.format("Failed to execute SQL scripts for test context %s: " +
205200
"cannot execute SQL scripts using Transaction Mode " +
206201
"[%s] without a PlatformTransactionManager.", testContext, TransactionMode.ISOLATED));
207-
208202
Assert.state(dataSource != null, () -> String.format("Failed to execute SQL scripts for test context %s: " +
209203
"supply at least a DataSource or PlatformTransactionManager.", testContext));
210-
211204
// Execute scripts directly against the DataSource
212205
populator.execute(dataSource);
213206
}
214207
else {
215-
DataSource dataSourceFromTxMgr = getDataSourceFromTransactionManager(transactionManager);
216-
208+
DataSource dataSourceFromTxMgr = getDataSourceFromTransactionManager(txMgr);
217209
// Ensure user configured an appropriate DataSource/TransactionManager pair.
218210
if (dataSource != null && dataSourceFromTxMgr != null && !dataSource.equals(dataSourceFromTxMgr)) {
219211
throw new IllegalStateException(String.format("Failed to execute SQL scripts for test context %s: " +
220212
"the configured DataSource [%s] (named '%s') is not the one associated with " +
221213
"transaction manager [%s] (named '%s').", testContext, dataSource.getClass().getName(),
222-
dsName, transactionManager.getClass().getName(), tmName));
214+
dsName, txMgr.getClass().getName(), tmName));
223215
}
224-
225216
if (dataSource == null) {
226217
dataSource = dataSourceFromTxMgr;
227-
Assert.state(dataSource != null, () -> String.format("Failed to execute SQL scripts for test context %s: " +
228-
"could not obtain DataSource from transaction manager [%s] (named '%s').", testContext,
229-
transactionManager.getClass().getName(), tmName));
218+
Assert.state(dataSource != null, () -> String.format("Failed to execute SQL scripts for " +
219+
"test context %s: could not obtain DataSource from transaction manager [%s] (named '%s').",
220+
testContext, txMgr.getClass().getName(), tmName));
230221
}
231-
232222
final DataSource finalDataSource = dataSource;
233223
int propagation = (newTxRequired ? TransactionDefinition.PROPAGATION_REQUIRES_NEW :
234224
TransactionDefinition.PROPAGATION_REQUIRED);
235-
236-
TransactionAttribute transactionAttribute = TestContextTransactionUtils.createDelegatingTransactionAttribute(
237-
testContext, new DefaultTransactionAttribute(propagation));
238-
239-
new TransactionTemplate(transactionManager, transactionAttribute).execute(status -> {
225+
TransactionAttribute txAttr = TestContextTransactionUtils.createDelegatingTransactionAttribute(
226+
testContext, new DefaultTransactionAttribute(propagation));
227+
new TransactionTemplate(txMgr, txAttr).execute(status -> {
240228
populator.execute(finalDataSource);
241229
return null;
242230
});
@@ -260,7 +248,7 @@ private DataSource getDataSourceFromTransactionManager(PlatformTransactionManage
260248
private String[] getScripts(Sql sql, TestContext testContext, boolean classLevel) {
261249
String[] scripts = sql.scripts();
262250
if (ObjectUtils.isEmpty(scripts) && ObjectUtils.isEmpty(sql.statements())) {
263-
scripts = new String[] { detectDefaultScript(testContext, classLevel) };
251+
scripts = new String[] {detectDefaultScript(testContext, classLevel)};
264252
}
265253
return scripts;
266254
}
@@ -286,8 +274,8 @@ private String detectDefaultScript(TestContext testContext, boolean classLevel)
286274

287275
if (classPathResource.exists()) {
288276
if (logger.isInfoEnabled()) {
289-
logger.info(String.format("Detected default SQL script \"%s\" for test %s [%s]", prefixedResourcePath,
290-
elementType, elementName));
277+
logger.info(String.format("Detected default SQL script \"%s\" for test %s [%s]",
278+
prefixedResourcePath, elementType, elementName));
291279
}
292280
return prefixedResourcePath;
293281
}

spring-test/src/main/java/org/springframework/test/context/support/ActiveProfilesUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static String[] resolveActiveProfiles(Class<?> testClass) {
8686
ActiveProfiles annotation = descriptor.synthesizeAnnotation();
8787

8888
if (logger.isTraceEnabled()) {
89-
logger.trace(String.format("Retrieved @ActiveProfiles [%s] for declaring class [%s].",
89+
logger.trace(String.format("Retrieved @ActiveProfiles [%s] for declaring class [%s]",
9090
annotation, declaringClass.getName()));
9191
}
9292

@@ -101,15 +101,15 @@ static String[] resolveActiveProfiles(Class<?> testClass) {
101101
}
102102
catch (Exception ex) {
103103
String msg = String.format("Could not instantiate ActiveProfilesResolver of type [%s] " +
104-
"for test class [%s].", resolverClass.getName(), rootDeclaringClass.getName());
104+
"for test class [%s]", resolverClass.getName(), rootDeclaringClass.getName());
105105
logger.error(msg);
106106
throw new IllegalStateException(msg, ex);
107107
}
108108

109109
String[] profiles = resolver.resolve(rootDeclaringClass);
110110
if (profiles == null) {
111111
String msg = String.format(
112-
"ActiveProfilesResolver [%s] returned a null array of bean definition profiles.",
112+
"ActiveProfilesResolver [%s] returned a null array of bean definition profiles",
113113
resolverClass.getName());
114114
logger.error(msg);
115115
throw new IllegalStateException(msg);

spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public MockHttpServletRequestBuilder contentType(String contentType) {
240240
* @param mediaTypes one or more media types
241241
*/
242242
public MockHttpServletRequestBuilder accept(MediaType... mediaTypes) {
243-
Assert.notEmpty(mediaTypes, "No 'Accept' media types");
243+
Assert.notEmpty(mediaTypes, "'mediaTypes' must not be empty");
244244
this.headers.set("Accept", MediaType.toString(Arrays.asList(mediaTypes)));
245245
return this;
246246
}
@@ -250,8 +250,8 @@ public MockHttpServletRequestBuilder accept(MediaType... mediaTypes) {
250250
* @param mediaTypes one or more media types
251251
*/
252252
public MockHttpServletRequestBuilder accept(String... mediaTypes) {
253-
Assert.notEmpty(mediaTypes, "No 'Accept' media types");
254-
List<MediaType> result = new ArrayList<>(mediaTypes.length);
253+
Assert.notEmpty(mediaTypes, "'mediaTypes' must not be empty");
254+
List<MediaType> result = new ArrayList<MediaType>(mediaTypes.length);
255255
for (String mediaType : mediaTypes) {
256256
result.add(MediaType.parseMediaType(mediaType));
257257
}

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,22 @@ public class ResourceHandlerRegistry {
6262
private int order = Integer.MAX_VALUE -1;
6363

6464

65+
/**
66+
* Create a new resource handler registry for the given application context.
67+
* @param applicationContext the Spring application context
68+
* @param servletContext the corresponding Servlet context
69+
*/
6570
public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext) {
6671
this(applicationContext, servletContext, null);
6772
}
6873

74+
/**
75+
* Create a new resource handler registry for the given application context.
76+
* @param applicationContext the Spring application context
77+
* @param servletContext the corresponding Servlet context
78+
* @param contentNegotiationManager the content negotiation manager to use
79+
* @since 4.3
80+
*/
6981
public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext,
7082
ContentNegotiationManager contentNegotiationManager) {
7183

0 commit comments

Comments
 (0)