WorkerBinder { public static WorkerUnbinder bind(Interactor<?, ?> interactor, Worker worker) { return bind(interactor.lifecycle(), worker); } private  WorkerBinder(); static WorkerUnbinder bind(Interactor<?, ?> interactor, Worker worker); static void bind(Interactor interactor, List<? extends Worker> workers);  }
@Test public void bind_whenInteractorAttached_shouldStartWorker() { BehaviorRelay<InteractorEvent> lifecycle = BehaviorRelay.createDefault(InteractorEvent.ACTIVE); bind(lifecycle, worker); verify(worker).onStart(Matchers.<WorkerScopeProvider>any()); }
@Test public void bind_whenInteractorDetached_shouldStopWorker() { BehaviorRelay<InteractorEvent> lifecycle = BehaviorRelay.createDefault(InteractorEvent.ACTIVE); bind(lifecycle, worker); lifecycle.accept(InteractorEvent.INACTIVE); verify(worker).onStop(); }
@Test public void unbind_whenInteractorAttached_shouldStopWorker() { BehaviorRelay<InteractorEvent> lifecycle = BehaviorRelay.createDefault(InteractorEvent.ACTIVE); WorkerUnbinder unbinder = bind(lifecycle, worker); unbinder.unbind(); verify(worker).onStop(); }
@Test public void unbind_whenOutsideInteractorLifecycle_shouldNotCallStopAgain() { BehaviorRelay<InteractorEvent> lifecycle = BehaviorRelay.createDefault(InteractorEvent.INACTIVE); WorkerUnbinder unbinder = bind(lifecycle, worker); verify(worker, times(1)).onStop(); unbinder.unbind(); verify(worker, times(1)).onStop(); }
@Test public void onInactive_whenAfterUnbind_shouldNotCallStopAgain() { BehaviorRelay<InteractorEvent> lifecycle = BehaviorRelay.createDefault(InteractorEvent.ACTIVE); WorkerUnbinder unbinder = bind(lifecycle, worker); unbinder.unbind(); verify(worker, times(1)).onStop(); lifecycle.accept(InteractorEvent.INACTIVE); verify(worker, times(1)).onStop(); }