public void testDefaultReference() throws Exception {
BlueprintContainer blueprintContainer = Helper.getBlueprintContainerForBundle(context(), "org.apache.aries.blueprint.sample");
assertNotNull(blueprintContainer);
Runnable refRunnable = (Runnable) blueprintContainer.getComponentInstance("refWithDefault");
DefaultRunnable defaultRunnable = (DefaultRunnable) blueprintContainer.getComponentInstance("defaultRunnable");
refRunnable.run();
waitForAsynchronousHandling();
Thread.sleep(2000);
assertEquals("The default runnable was not called", 1, defaultRunnable.getCount());
Runnable mockService = Skeleton.newMock(Runnable.class);
ServiceRegistration reg = bundleContext.registerService(Runnable.class.getName(), mockService, null);
waitForAsynchronousHandling();
Thread.sleep(2000);
refRunnable.run();
assertEquals("The default runnable was called when a service was bound", 1, defaultRunnable.getCount());
Skeleton.getSkeleton(mockService).assertCalled(new MethodCall(Runnable.class, "run"));
reg.unregister();
waitForAsynchronousHandling();
Thread.sleep(2000);
refRunnable.run();
assertEquals("The default runnable was not called", 2, defaultRunnable.getCount());
}