Acacia { public static void stopService(Object aService) { for (Class<?> myInterface : aService.getClass().getInterfaces()) { Service serviceAnnotation = myInterface.getAnnotation(Service.class); if (serviceAnnotation != null) { try { Method stopMethod = ServiceControl.class.getDeclaredMethod("stop"); stopMethod.invoke(aService); } catch (Exception anEx) { Log.e(Constants.LOG_TAG, "Unable to stop service", anEx); } return; } } throw new AcaciaException("Given class " + aService.getClass().getName() + " is not a service interface (must be annotated " + "with " + Service.class.getName() + ")"); }  static T createService(Context aContext, Class<T> aServiceInterface); static void stopService(Object aService);  }
@Test(expected = IllegalStateException.class) public void testStopService() throws InterruptedException { TestServiceOnWorkerThread serviceInterface = Acacia.createService( Robolectric.application, TestServiceOnWorkerThread.class); Acacia.stopService(serviceInterface); assertTrue(shadowOf(androidService).isStoppedBySelf()); Class<? extends ServiceConnection> unboundConn = shadowOf(Robolectric.application). getUnboundServiceConnections().get(0).getClass(); assertEquals(ServiceProxy.class, unboundConn); serviceInterface.getIntPrimitive(); }