/**
* Test instances destroyed in proper (i.e. reverse) order
*/
public void testDestroyOrder() throws Exception {
EventContext ctx = new EventContextImpl();
RequestScopeContext scope = new RequestScopeContext(ctx);
scope.registerFactories(createOrderedInitComponents());
scope.start();
// request start
RequestScopedOrderedInitPojo one = (RequestScopedOrderedInitPojo) scope.getContext("one").getInstance(null);
Assert.assertNotNull(one);
Assert.assertEquals(1, one.getNumberInstantiated());
Assert.assertEquals(1, one.getInitOrder());
RequestScopedOrderedInitPojo two = (RequestScopedOrderedInitPojo) scope.getContext("two").getInstance(null);
Assert.assertNotNull(two);
Assert.assertEquals(2, two.getNumberInstantiated());
Assert.assertEquals(2, two.getInitOrder());
RequestScopedOrderedInitPojo three = (RequestScopedOrderedInitPojo) scope.getContext("three").getInstance(null);
Assert.assertNotNull(three);
Assert.assertEquals(3, three.getNumberInstantiated());
Assert.assertEquals(3, three.getInitOrder());
// end request
scope.onEvent(new RequestEnd(this, new Object()));
Assert.assertEquals(0, one.getNumberInstantiated());
scope.stop();
}