WithSecurityContextTestExecutionListener Supports Nested Classes
WithSecurityContextTestExecutionListener now supports nested classes. If the class is nested WithSecurityContext is not found, then the enclosing class is looked at until there is no enclosing class. Closes gh-9179
This commit is contained in:
@@ -92,6 +92,30 @@ public class WithSecurityContextTestExcecutionListenerTests {
|
||||
assertThat(TestSecurityContextHolder.getContext().getAuthentication().getName()).isEqualTo("user");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void beforeTestMethodInnerClass() throws Exception {
|
||||
Class testClass = OuterClass.InnerClass.class;
|
||||
Method testNoAnnotation = ReflectionUtils.findMethod(testClass, "testNoAnnotation");
|
||||
given(this.testContext.getTestClass()).willReturn(testClass);
|
||||
given(this.testContext.getTestMethod()).willReturn(testNoAnnotation);
|
||||
given(this.testContext.getApplicationContext()).willThrow(new IllegalStateException(""));
|
||||
this.listener.beforeTestMethod(this.testContext);
|
||||
assertThat(TestSecurityContextHolder.getContext().getAuthentication().getName()).isEqualTo("user");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void beforeTestMethodInnerInnerClass() throws Exception {
|
||||
Class testClass = OuterClass.InnerClass.InnerInnerClass.class;
|
||||
Method testNoAnnotation = ReflectionUtils.findMethod(testClass, "testNoAnnotation");
|
||||
given(this.testContext.getTestClass()).willReturn(testClass);
|
||||
given(this.testContext.getTestMethod()).willReturn(testNoAnnotation);
|
||||
given(this.testContext.getApplicationContext()).willThrow(new IllegalStateException(""));
|
||||
this.listener.beforeTestMethod(this.testContext);
|
||||
assertThat(TestSecurityContextHolder.getContext().getAuthentication().getName()).isEqualTo("user");
|
||||
}
|
||||
|
||||
// gh-3962
|
||||
@Test
|
||||
public void withSecurityContextAfterSqlScripts() {
|
||||
@@ -166,4 +190,23 @@ public class WithSecurityContextTestExcecutionListenerTests {
|
||||
|
||||
}
|
||||
|
||||
@WithMockUser
|
||||
static class OuterClass {
|
||||
|
||||
static class InnerClass {
|
||||
|
||||
void testNoAnnotation() {
|
||||
}
|
||||
|
||||
static class InnerInnerClass {
|
||||
|
||||
void testNoAnnotation() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user