Polishing
This commit is contained in:
@@ -112,8 +112,8 @@ public class MockAsyncContext implements AsyncContext {
|
||||
try {
|
||||
listener.onComplete(new AsyncEvent(this, this.request, this.response));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException("AsyncListener failure", e);
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("AsyncListener failure", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.test.context.jdbc;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -216,10 +215,10 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
|
||||
DataSource dataSourceFromTxMgr = getDataSourceFromTransactionManager(transactionManager);
|
||||
|
||||
// Ensure user configured an appropriate DataSource/TransactionManager pair.
|
||||
if ((dataSource != null) && (dataSourceFromTxMgr != null) && !dataSource.equals(dataSourceFromTxMgr)) {
|
||||
throw new IllegalStateException(String.format("Failed to execute SQL scripts for test context %s: "
|
||||
+ "the configured DataSource [%s] (named '%s') is not the one associated "
|
||||
+ "with transaction manager [%s] (named '%s').", testContext, dataSource.getClass().getName(),
|
||||
if (dataSource != null && dataSourceFromTxMgr != null && !dataSource.equals(dataSourceFromTxMgr)) {
|
||||
throw new IllegalStateException(String.format("Failed to execute SQL scripts for test context %s: " +
|
||||
"the configured DataSource [%s] (named '%s') is not the one associated with " +
|
||||
"transaction manager [%s] (named '%s').", testContext, dataSource.getClass().getName(),
|
||||
dsName, transactionManager.getClass().getName(), tmName));
|
||||
}
|
||||
|
||||
@@ -231,8 +230,8 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
|
||||
}
|
||||
|
||||
final DataSource finalDataSource = dataSource;
|
||||
int propagation = newTxRequired ? TransactionDefinition.PROPAGATION_REQUIRES_NEW
|
||||
: TransactionDefinition.PROPAGATION_REQUIRED;
|
||||
int propagation = (newTxRequired ? TransactionDefinition.PROPAGATION_REQUIRES_NEW :
|
||||
TransactionDefinition.PROPAGATION_REQUIRED);
|
||||
|
||||
TransactionAttribute transactionAttribute = TestContextTransactionUtils.createDelegatingTransactionAttribute(
|
||||
testContext, new DefaultTransactionAttribute(propagation));
|
||||
@@ -252,8 +251,8 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
|
||||
return (DataSource) obj;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
/* ignore */
|
||||
catch (Exception ex) {
|
||||
// ignore
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -293,9 +292,9 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
|
||||
return prefixedResourcePath;
|
||||
}
|
||||
else {
|
||||
String msg = String.format("Could not detect default SQL script for test %s [%s]: "
|
||||
+ "%s does not exist. Either declare statements or scripts via @Sql or make the "
|
||||
+ "default SQL script available.", elementType, elementName, classPathResource);
|
||||
String msg = String.format("Could not detect default SQL script for test %s [%s]: " +
|
||||
"%s does not exist. Either declare statements or scripts via @Sql or make the " +
|
||||
"default SQL script available.", elementType, elementName, classPathResource);
|
||||
logger.error(msg);
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
|
||||
@@ -52,18 +52,12 @@ abstract class ActiveProfilesUtils {
|
||||
private static final Log logger = LogFactory.getLog(ActiveProfilesUtils.class);
|
||||
|
||||
|
||||
private ActiveProfilesUtils() {
|
||||
/* no-op */
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve <em>active bean definition profiles</em> for the supplied {@link Class}.
|
||||
*
|
||||
* <p>Note that the {@link ActiveProfiles#inheritProfiles inheritProfiles} flag of
|
||||
* {@link ActiveProfiles @ActiveProfiles} will be taken into consideration.
|
||||
* Specifically, if the {@code inheritProfiles} flag is set to {@code true}, profiles
|
||||
* defined in the test class will be merged with those defined in superclasses.
|
||||
*
|
||||
* @param testClass the class for which to resolve the active profiles (must not be
|
||||
* {@code null})
|
||||
* @return the set of active profiles for the specified class, including active
|
||||
@@ -78,12 +72,12 @@ abstract class ActiveProfilesUtils {
|
||||
final List<String[]> profileArrays = new ArrayList<>();
|
||||
|
||||
Class<ActiveProfiles> annotationType = ActiveProfiles.class;
|
||||
AnnotationDescriptor<ActiveProfiles> descriptor = MetaAnnotationUtils.findAnnotationDescriptor(testClass,
|
||||
annotationType);
|
||||
AnnotationDescriptor<ActiveProfiles> descriptor =
|
||||
MetaAnnotationUtils.findAnnotationDescriptor(testClass, annotationType);
|
||||
if (descriptor == null && logger.isDebugEnabled()) {
|
||||
logger.debug(String.format(
|
||||
"Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]",
|
||||
annotationType.getName(), testClass.getName()));
|
||||
"Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]",
|
||||
annotationType.getName(), testClass.getName()));
|
||||
}
|
||||
|
||||
while (descriptor != null) {
|
||||
@@ -92,8 +86,8 @@ abstract class ActiveProfilesUtils {
|
||||
ActiveProfiles annotation = descriptor.synthesizeAnnotation();
|
||||
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace(String.format("Retrieved @ActiveProfiles [%s] for declaring class [%s].", annotation,
|
||||
declaringClass.getName()));
|
||||
logger.trace(String.format("Retrieved @ActiveProfiles [%s] for declaring class [%s].",
|
||||
annotation, declaringClass.getName()));
|
||||
}
|
||||
|
||||
Class<? extends ActiveProfilesResolver> resolverClass = annotation.resolver();
|
||||
@@ -101,22 +95,22 @@ abstract class ActiveProfilesUtils {
|
||||
resolverClass = DefaultActiveProfilesResolver.class;
|
||||
}
|
||||
|
||||
ActiveProfilesResolver resolver = null;
|
||||
ActiveProfilesResolver resolver;
|
||||
try {
|
||||
resolver = BeanUtils.instantiateClass(resolverClass, ActiveProfilesResolver.class);
|
||||
}
|
||||
catch (Exception e) {
|
||||
String msg = String.format("Could not instantiate ActiveProfilesResolver of "
|
||||
+ "type [%s] for test class [%s].", resolverClass.getName(), rootDeclaringClass.getName());
|
||||
catch (Exception ex) {
|
||||
String msg = String.format("Could not instantiate ActiveProfilesResolver of type [%s] " +
|
||||
"for test class [%s].", resolverClass.getName(), rootDeclaringClass.getName());
|
||||
logger.error(msg);
|
||||
throw new IllegalStateException(msg, e);
|
||||
throw new IllegalStateException(msg, ex);
|
||||
}
|
||||
|
||||
String[] profiles = resolver.resolve(rootDeclaringClass);
|
||||
if (profiles == null) {
|
||||
String msg = String.format(
|
||||
"ActiveProfilesResolver [%s] returned a null array of bean definition profiles.",
|
||||
resolverClass.getName());
|
||||
"ActiveProfilesResolver [%s] returned a null array of bean definition profiles.",
|
||||
resolverClass.getName());
|
||||
logger.error(msg);
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
@@ -124,7 +118,7 @@ abstract class ActiveProfilesUtils {
|
||||
profileArrays.add(profiles);
|
||||
|
||||
descriptor = (annotation.inheritProfiles() ? MetaAnnotationUtils.findAnnotationDescriptor(
|
||||
rootDeclaringClass.getSuperclass(), annotationType) : null);
|
||||
rootDeclaringClass.getSuperclass(), annotationType) : null);
|
||||
}
|
||||
|
||||
// Reverse the list so that we can traverse "down" the hierarchy.
|
||||
|
||||
@@ -42,7 +42,6 @@ public class AopTestUtils {
|
||||
* {@linkplain AopUtils#isAopProxy proxy}, the target of the proxy will
|
||||
* be returned; otherwise, the {@code candidate} will be returned
|
||||
* <em>as is</em>.
|
||||
*
|
||||
* @param candidate the instance to check (potentially a Spring AOP proxy);
|
||||
* never {@code null}
|
||||
* @return the target object or the {@code candidate}; never {@code null}
|
||||
@@ -58,8 +57,8 @@ public class AopTestUtils {
|
||||
return (T) ((Advised) candidate).getTargetSource().getTarget();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to unwrap proxied object.", e);
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Failed to unwrap proxied object", ex);
|
||||
}
|
||||
return (T) candidate;
|
||||
}
|
||||
@@ -72,7 +71,6 @@ public class AopTestUtils {
|
||||
* {@linkplain AopUtils#isAopProxy proxy}, the ultimate target of all
|
||||
* nested proxies will be returned; otherwise, the {@code candidate}
|
||||
* will be returned <em>as is</em>.
|
||||
*
|
||||
* @param candidate the instance to check (potentially a Spring AOP proxy);
|
||||
* never {@code null}
|
||||
* @return the ultimate target object or the {@code candidate}; never
|
||||
@@ -89,8 +87,8 @@ public class AopTestUtils {
|
||||
return (T) getUltimateTargetObject(((Advised) candidate).getTargetSource().getTarget());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to unwrap proxied object.", e);
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Failed to unwrap proxied object", ex);
|
||||
}
|
||||
return (T) candidate;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.test.web.client.match;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -192,8 +193,8 @@ public class XpathRequestMatchers {
|
||||
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
|
||||
matchInternal(mockRequest);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new AssertionError("Failed to parse XML request content: " + e.getMessage());
|
||||
catch (Exception ex) {
|
||||
throw new AssertionError("Failed to parse XML request content: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ final class MockWebResponseBuilder {
|
||||
result.setExpiryDate(expires);
|
||||
result.setPath(cookie.getPath());
|
||||
result.setSecure(cookie.getSecure());
|
||||
if(cookie.isHttpOnly()) {
|
||||
if (cookie.isHttpOnly()) {
|
||||
result.setAttribute("httponly", "true");
|
||||
}
|
||||
return new com.gargoylesoftware.htmlunit.util.Cookie(result);
|
||||
|
||||
Reference in New Issue
Block a user