@Before public void setUp() throws RemoteException { controller = Robolectric.buildActivity(Activity.class); activity = controller.create().get(); delegate = new CustomTabsDelegate(); service = mock(ICustomTabsService.class); when(service.newSession(any(ICustomTabsCallback.class))).thenReturn(true); IBinder binder = mock(IBinder.class); when(binder.queryLocalInterface(any())).thenReturn(service); ShadowApplication.getInstance() .setComponentNameAndServiceForBindService(mock(ComponentName.class), binder); }
@Test public void bindServiceShouldCallOnServiceConnectedWithDefaultValues() { TestService service = new TestService(); ComponentName expectedComponentName = new ComponentName("", ""); Binder expectedBinder = new Binder(); Shadows.shadowOf(context) .setComponentNameAndServiceForBindService(expectedComponentName, expectedBinder); context.bindService(new Intent(""), service, Context.BIND_AUTO_CREATE); assertThat(service.name).isEqualTo(expectedComponentName); assertThat(service.service).isEqualTo(expectedBinder); assertThat(service.nameUnbound).isNull(); context.unbindService(service); assertThat(service.nameUnbound).isEqualTo(expectedComponentName); }
public void setServiceForBinding(final Bundle stubBundle) { ShadowApplication shadowApplication = shadowOf(RuntimeEnvironment.application); IInAppBillingService.Stub stub = create(stubBundle); ComponentName cn = mock(ComponentName.class); shadowApplication.setComponentNameAndServiceForBindService(cn, stub); }
public void setServiceForBinding(final Bundle stubBundle) { ShadowApplication shadowApplication = shadowOf(RuntimeEnvironment.application); IInAppBillingService.Stub stub = create(stubBundle); ComponentName cn = mock(ComponentName.class); shadowApplication.setComponentNameAndServiceForBindService(cn, stub); }
public static JobInfo.Builder create(Context context, int id, long delay) { JobInfo.Builder builder; if (delay > 0) { ComponentName component = new ComponentName(context, NoopAsyncJobService.class); PersistableBundle extras = new PersistableBundle(); extras.putLong(NoopAsyncJobService.EXTRA_DELAY, delay); builder = new JobInfo.Builder(id, component).setExtras(extras); ShadowApplication.getInstance().setComponentNameAndServiceForBindService( component, new NoopAsyncJobService().onBind(null)); } else { ComponentName component = new ComponentName(context, NoopJobService.class); builder = new JobInfo.Builder(id, component); ShadowApplication.getInstance().setComponentNameAndServiceForBindService( component, new NoopJobService().onBind(null)); } return builder; }
@Before public void init() { context = Robolectric.setupActivity(Activity.class); shadowContext = Shadows.shadowOf(context); testingQueues = new TestingQueues(); serviceInstance = spy(new Goro.GoroImpl(testingQueues)); serviceCompName = new ComponentName(context, GoroService.class); GoroService service = new GoroService(); binder = new GoroService.GoroBinderImpl(serviceInstance, service.new GoroTasksListener()); ShadowApplication.getInstance() .setComponentNameAndServiceForBindService( serviceCompName, binder ); reset(serviceInstance); }