BoundGoro extends BufferedGoroDelegate { public abstract void bind();  abstract void bind(); abstract void unbind();  }
@Test public void removeListenerShouldRemoveFromRecords() { GoroListener listener = mock(GoroListener.class); goro.addTaskListener(listener); goro.removeTaskListener(listener); goro.bind(); assertBinding(); verify(serviceInstance, never()).addTaskListener(listener); }
@Test public void cancelFutureBeforeBindingShouldRemoveRecordedTask() { Future<?> future = goro.schedule(mock(Callable.class)); future.cancel(true); goro.bind(); assertBinding(); verify(serviceInstance, never()).schedule(anyString(), any(Callable.class)); }
@Test public void getExecutorShouldReturnExecutorWrapper() { Executor executor = goro.getExecutor("q"); assertThat(executor).isNotNull(); Runnable task = mock(Runnable.class); executor.execute(task); verify(task, never()).run(); Executor direct = new Executor() { @Override public void execute(Runnable command) { command.run(); } }; doReturn(direct).when(serviceInstance).getExecutor(anyString()); goro.bind(); verify(task).run(); }
@Test public void clearShouldNotBePostponedAfterDelegation() { goro = (BoundGoro.BoundGoroImpl) Goro.bindAndAutoReconnectWith(context); goro.bind(); goro.clear("a"); goro.onServiceDisconnected(new ComponentName("any", "any")); verify(serviceInstance).clear("a"); }
@Test public void disconnectionHandlerIsInvoked() { goro.bind(); assertBinding(); goro.onServiceDisconnected(new ComponentName("test", "test")); verify(disconnection).onServiceDisconnected(goro); }
@Test public void autoReconnection() { goro = (BoundGoro.BoundGoroImpl) spy(Goro.bindAndAutoReconnectWith(context)); goro.bind(); assertBinding(); reset(goro); goro.onServiceDisconnected(new ComponentName("test", "test")); assertBinding(); }
@Test public void afterBindingScheduleShouldBeDelegated() { goro.bind(); Callable<?> task = mock(Callable.class); ObservableFuture<?> future = mock(ObservableFuture.class); doReturn(future).when(serviceInstance).schedule("2", task); assertThat((Object) goro.schedule("2", task)).isSameAs(future); }