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