ServiceDecoratorBundleListener implements BundleListener { @Override public void bundleChanged(BundleEvent be) { switch(be.getType()) { case BundleEvent.STARTED: this.serviceDecorator.addDecorations(be.getBundle()); break; case BundleEvent.STOPPING: this.serviceDecorator.removeDecorations(be.getBundle()); break; default: } } ServiceDecoratorBundleListener(ServiceDecoratorImpl serviceDecorator); @Override void bundleChanged(BundleEvent be);  }
@Test public void testBundleListener() { BundleContext bc = EasyMock.createMock(BundleContext.class); EasyMock.replay(bc); final List<String> called = new ArrayList<>(); ServiceDecoratorImpl serviceDecorator = new ServiceDecoratorImpl() { @Override void addDecorations(Bundle bundle) { called.add("addDecorations"); } @Override void removeDecorations(Bundle bundle) { called.add("removeDecorations"); } }; Bundle b = EasyMock.createMock(Bundle.class); EasyMock.replay(b); ServiceDecoratorBundleListener listener = new ServiceDecoratorBundleListener(serviceDecorator); assertEquals("Precondition failed", 0, called.size()); listener.bundleChanged(new BundleEvent(BundleEvent.INSTALLED, b)); assertEquals(0, called.size()); listener.bundleChanged(new BundleEvent(BundleEvent.STARTED, b)); assertEquals(Arrays.asList("addDecorations"), called); listener.bundleChanged(new BundleEvent(BundleEvent.STOPPING, b)); assertEquals(Arrays.asList("addDecorations", "removeDecorations"), called); }