Acacia { public static <T> T createService(Context aContext, Class<T> aServiceInterface) { return ServiceProxy.newInstance(aContext, aServiceInterface); }  static T createService(Context aContext, Class<T> aServiceInterface); static void stopService(Object aService);  }
@Test public void testObservableOnWorkerThread() { serviceImpl.setTestObservable(Observable.just("Hello")); TestServiceOnWorkerThread serviceInterface = Acacia.createService( Robolectric.application, TestServiceOnWorkerThread.class); serviceInterface.getObservable() .subscribe(new Action1<String>() { @Override public void call(String o) { assertEquals("Hello", o); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { error = throwable; } }); assertNotNull(androidService.getServiceThread()); shadowOf(androidService.getServiceThread().getHandler().getLooper()).idle(); assertNotErrors(); }
@Test public void testObservableOnCallerThread() { serviceImpl.setTestObservable(Observable.just("Hello")); TestServiceOnCallerThread serviceInterface = Acacia.createService( Robolectric.application, TestServiceOnCallerThread.class); serviceInterface.getObservable() .subscribe(new Action1<String>() { @Override public void call(String o) { assertEquals("Hello", o); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { error = throwable; } }); assertNull(androidService.getServiceThread()); assertNotErrors(); }
@Test public void testNullObservableOnWorkerThread() { serviceImpl.setTestObservable(null); TestServiceOnWorkerThread serviceInterface = Acacia.createService( Robolectric.application, TestServiceOnWorkerThread.class); assertNull(serviceInterface.getObservable()); }
@Test public void testNullObservableOnCallerThread() { androidService.setUserImpl(serviceImpl); serviceImpl.setTestObservable(null); TestServiceOnCallerThread serviceInterface = Acacia.createService( Robolectric.application, TestServiceOnCallerThread.class); assertNull(serviceInterface.getObservable()); }
@Test public void testPrimitiveOnWorkerThread() { serviceImpl.setTestIntPrimitive(77); TestServiceOnWorkerThread serviceInterface = Acacia.createService( Robolectric.application, TestServiceOnWorkerThread.class); assertEquals(77, serviceInterface.getIntPrimitive()); assertNotNull(androidService.getServiceThread()); }
@Test public void testPrimitiveOnCallerThread() { serviceImpl.setTestIntPrimitive(77); TestServiceOnCallerThread serviceInterface = Acacia.createService( Robolectric.application, TestServiceOnCallerThread.class); assertEquals(77, serviceInterface.getIntPrimitive()); assertNull(androidService.getServiceThread()); }