OsgiDefaultConsumer extends ServiceSupport implements Consumer, SuspendableService, Processor { @Override protected void doSuspend() throws Exception { unregister(); } OsgiDefaultConsumer(OsgiDefaultEndpoint endpoint, Processor processor, Map<String, Object> props); @Override OsgiDefaultEndpoint getEndpoint(); @Override void process(final Exchange exchange);  }
@Test public void testDoSuspend() throws Exception { ServiceRegistration registration = mock(ServiceRegistration.class); BundleContext bundleContext = mock(BundleContext.class); when(bundleContext.registerService(eq(OsgiComponent.OBJECT_CLASS), anyObject(), any(Dictionary.class))) .thenReturn(registration); OsgiDefaultEndpoint endpoint = mock(OsgiDefaultEndpoint.class); when(endpoint.getApplicationBundleContext()).thenReturn(bundleContext); Service processor = mock(Service.class, withSettings().extraInterfaces(Processor.class)); OsgiDefaultConsumer consumer = new OsgiDefaultConsumer( endpoint, (Processor) processor, Collections.<String, Object>emptyMap()); ServiceHelper.startService(consumer); ServiceHelper.suspendService(consumer); ServiceHelper.resumeService(consumer); ServiceHelper.suspendService(consumer); verify(processor, never()).stop(); verify(registration, times(2)).unregister(); }