Search in sources :

Example 11 with TestContext

use of org.springframework.test.context.TestContext in project spring-security by spring-projects.

the class WithSecurityContextTestExcecutionListenerTests method handlesGenericAnnotation.

@Test
public // gh-3837
void handlesGenericAnnotation() throws Exception {
    Method method = ReflectionUtils.findMethod(WithSecurityContextTestExcecutionListenerTests.class, "handlesGenericAnnotationTestMethod");
    TestContext testContext = mock(TestContext.class);
    when(testContext.getTestMethod()).thenReturn(method);
    when(testContext.getApplicationContext()).thenThrow(new IllegalStateException(""));
    this.listener.beforeTestMethod(testContext);
    assertThat(SecurityContextHolder.getContext().getAuthentication().getPrincipal()).isInstanceOf(WithSuperClassWithSecurityContext.class);
}
Also used : TestContext(org.springframework.test.context.TestContext) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

TestContext (org.springframework.test.context.TestContext)11 Test (org.junit.Test)8 Method (java.lang.reflect.Method)1 SpringApplication (org.springframework.boot.SpringApplication)1 WebEnvironment (org.springframework.boot.test.context.SpringBootTest.WebEnvironment)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 MergedContextConfiguration (org.springframework.test.context.MergedContextConfiguration)1