use of org.springframework.context.event.ApplicationContextEvent in project tephra by heisedebaise.
the class ContainerTest method contextClosed.
@Test
public void contextClosed() throws Exception {
for (int i = 0; i < 2; i++) {
((ContainerImpl) container).onApplicationEvent(new ContextClosedEvent(getApplicationContext()));
Assert.assertEquals(2 + i * 2, contextClosedList.size());
for (int j = 0; j < contextRefreshedList.size(); j++) Assert.assertEquals(j % 2 + 1, numeric.toInt(contextClosedList.get(j)));
}
Field field = ContainerImpl.class.getDeclaredField("closedListeners");
field.setAccessible(true);
Object object = field.get(container);
field.set(container, Optional.empty());
for (int i = 0; i < 2; i++) {
((ContainerImpl) container).onApplicationEvent(new ContextClosedEvent(getApplicationContext()));
Assert.assertEquals(4, contextClosedList.size());
for (int j = 0; j < contextClosedList.size(); j++) Assert.assertEquals(j % 2 + 1, numeric.toInt(contextClosedList.get(j)));
}
((ContainerImpl) container).onApplicationEvent(new ApplicationContextEvent(getApplicationContext()) {
});
Assert.assertEquals(4, contextClosedList.size());
for (int i = 0; i < contextClosedList.size(); i++) Assert.assertEquals(i % 2 + 1, numeric.toInt(contextClosedList.get(i)));
field.set(container, object);
}
use of org.springframework.context.event.ApplicationContextEvent in project tephra by heisedebaise.
the class ContainerTest method contextRefreshed.
@Test
public void contextRefreshed() throws Exception {
Assert.assertEquals(2, contextRefreshedList.size());
for (int i = 0; i < contextRefreshedList.size(); i++) Assert.assertEquals(i + 1, numeric.toInt(contextRefreshedList.get(i)));
for (int i = 0; i < 2; i++) {
((ContainerImpl) container).onApplicationEvent(new ContextRefreshedEvent(getApplicationContext()));
Assert.assertEquals(4 + i * 2, contextRefreshedList.size());
for (int j = 0; j < contextRefreshedList.size(); j++) Assert.assertEquals(j % 2 + 1, numeric.toInt(contextRefreshedList.get(j)));
}
Field field = ContainerImpl.class.getDeclaredField("refreshedListeners");
field.setAccessible(true);
Object object = field.get(container);
field.set(container, Optional.empty());
for (int i = 0; i < 2; i++) {
((ContainerImpl) container).onApplicationEvent(new ContextRefreshedEvent(getApplicationContext()));
Assert.assertEquals(6, contextRefreshedList.size());
for (int j = 0; j < contextRefreshedList.size(); j++) Assert.assertEquals(j % 2 + 1, numeric.toInt(contextRefreshedList.get(j)));
}
((ContainerImpl) container).onApplicationEvent(new ApplicationContextEvent(getApplicationContext()) {
});
Assert.assertEquals(6, contextRefreshedList.size());
for (int i = 0; i < contextRefreshedList.size(); i++) Assert.assertEquals(i % 2 + 1, numeric.toInt(contextRefreshedList.get(i)));
field.set(container, object);
}
Aggregations