Format WithSecurityContextTestExecutionListener

This commit is contained in:
Rob Winch 2016-05-20 09:36:58 -05:00
parent 336de35874
commit 101190ad8b
1 changed files with 8 additions and 7 deletions

View File

@ -43,9 +43,8 @@ import org.springframework.test.web.servlet.MockMvc;
* @author Eddú Meléndez
* @since 4.0
*/
public class WithSecurityContextTestExecutionListener extends
AbstractTestExecutionListener {
public class WithSecurityContextTestExecutionListener
extends AbstractTestExecutionListener {
/**
* Sets up the {@link SecurityContext} for each test method. First the specific method
@ -55,10 +54,11 @@ public class WithSecurityContextTestExecutionListener extends
*/
@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
SecurityContext securityContext = createSecurityContext(testContext.getTestMethod(),
testContext);
SecurityContext securityContext = createSecurityContext(
testContext.getTestMethod(), testContext);
if (securityContext == null) {
securityContext = createSecurityContext(testContext.getTestClass(), testContext);
securityContext = createSecurityContext(testContext.getTestClass(),
testContext);
}
if (securityContext != null) {
TestSecurityContextHolder.setContext(securityContext);
@ -123,7 +123,8 @@ public class WithSecurityContextTestExecutionListener extends
Class<? extends WithSecurityContextFactory<? extends Annotation>> clazz = withSecurityContext
.factory();
try {
return testContext.getApplicationContext().getAutowireCapableBeanFactory().createBean(clazz);
return testContext.getApplicationContext().getAutowireCapableBeanFactory()
.createBean(clazz);
}
catch (IllegalStateException e) {
return BeanUtils.instantiateClass(clazz);