// capture the BundleListener registered with BundleContext to issue BundleEvents
ArgumentCaptor<BundleListener> argument = ArgumentCaptor.forClass(BundleListener.class);
verify(context).addBundleListener(argument.capture());
//send events
BundleListener listener = argument.getValue();
listener.bundleChanged(installedEvent);
listener.bundleChanged(resolvedEvent);
//shutdown dispatcher via unregister callback
bundleState.postDeregister();
//check the BundleListener is cleaned up
verify(context).removeBundleListener(listener);