Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrya committed Mar 1, 2021
1 parent 673f6ad commit d5655f5
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void chain_is_set_up_correctly() {
.map(this::wrapAsSpy)
.collect(Collectors.toList());

InitializationHandler.getHandler(handlerChain);
InitializationHandler.getHandler(context, handlerChain);

assertThat(handlerSpies).hasSize(6);
assertThat(handlerSpies.get(0)).isInstanceOf(EnsureLocationPermission.class);
Expand All @@ -71,21 +71,21 @@ public void all_states_are_passed() {
doReturn(false).when(context).isLocationServiceNeeded();
doReturn(powerManager).when(context).getSystemService(POWER_SERVICE);

InitializationHandler handler = InitializationHandler.getHandler(handlerChain);
InitializationHandler handler = InitializationHandler.getHandler(context, handlerChain);
// scheduler needs too many android classes to mock properly for now
doNothing().when(handlerSpies.get(5)).initialize(context);
doNothing().when(handlerSpies.get(5)).initialize();

handler.initialize(context);
handler.initialize();

InOrder inOrder = inOrder(handlerSpies.toArray());
handlerSpies.forEach(handlerSpy -> inOrder.verify(handlerSpy).initialize(context));
handlerSpies.forEach(handlerSpy -> inOrder.verify(handlerSpy).initialize());

inOrder.verifyNoMoreInteractions();
}

HandlerFactory wrapAsSpy(HandlerFactory original) {
return handlerChain -> {
InitializationHandler spyHandler = spy(original.create(handlerChain));
return (activity, handlerChain) -> {
InitializationHandler spyHandler = spy(original.create(activity, handlerChain));
// as each handler creates all its next handlers in its constructor,
// the spies are created in reverse order to the initial chain
handlerSpies.addFirst((AbstractChainedHandler<?, ?>) spyHandler);
Expand Down

0 comments on commit d5655f5

Please sign in to comment.