// need to clear the listener for testing
((DefaultCamelContextRegistry) CamelContextRegistry.INSTANCE).clear();
MyListener listener = new MyListener();
CamelContext camel1 = new DefaultCamelContext();
CamelContext camel2 = new DefaultCamelContext();
assertEquals(0, listener.names.size());
CamelContextRegistry.INSTANCE.addListener(listener, true);
// after we set, then we should manage the 2 pending contexts
assertEquals(2, listener.names.size());
CamelContext camel3 = new DefaultCamelContext();
assertEquals(3, listener.names.size());
assertEquals(camel1.getName(), listener.names.get(0));
assertEquals(camel2.getName(), listener.names.get(1));
assertEquals(camel3.getName(), listener.names.get(2));
camel1.stop();
camel2.stop();
camel3.stop();
assertEquals(0, listener.names.size());
}