I found, that uncommenting test listener annotation causes test not working below (autowired member is not initialized and NullPointerException occurs):
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = TestExecutionListenerTry2._Config.class)
//@TestExecutionListeners({TestExecutionListenerTry2._Listener.class})
public class TestExecutionListenerTry2 {
public static class Bean1 {
{
System.out.println("Bean1 constructor");
}
public void method() {
System.out.println("method()");
}
}
@Configuration
public static class _Config {
@Bean
public Bean1 bean1() {
return new Bean1();
}
}
public static class _Listener extends AbstractTestExecutionListener {
@Override
public void prepareTestInstance(TestContext testContext) throws Exception {
System.out.println("prepareTestInstance");
}
@Override
public void beforeTestClass(TestContext testContext) throws Exception {
System.out.println("beforeTestClass");
}
}
@Autowired
public Bean1 bean1;
@Test
public void testMethod() {
bean1.method();
}
}
Why?