Test beforeTestMethod delays creation of SecurityContext

Issue gh-6591
This commit is contained in:
Rob Winch 2020-06-24 16:39:51 -05:00
parent 97ee6d66f1
commit dac7806cf5
1 changed files with 16 additions and 1 deletions

View File

@ -124,6 +124,18 @@ public class WithSecurityContextTestExecutionListenerTests {
assertThat(supplierCaptor.getValue().get().getAuthentication()).isNotNull();
}
@Test
// gh-6591
public void beforeTestMethodWhenTestExecutionThenDelayFactoryCreate() throws Exception {
Method testMethod = TheTest.class.getMethod("withUserDetails");
when(this.testContext.getApplicationContext()).thenReturn(this.applicationContext);
// do not set a UserDetailsService Bean so it would fail if looked up
when(this.testContext.getTestMethod()).thenReturn(testMethod);
this.listener.beforeTestMethod(this.testContext);
// bean lookup of UserDetailsService would fail if it has already been looked up
}
@Test
public void beforeTestExecutionWhenTestContextNullThenSecurityContextNotSet() {
this.listener.beforeTestExecution(this.testContext);
@ -158,7 +170,10 @@ public class WithSecurityContextTestExecutionListenerTests {
@WithMockUser
public void withMockUserDefault() {
}
@WithUserDetails(setupBefore = TestExecutionEvent.TEST_EXECUTION)
public void withUserDetails() {
}
}
}