use of io.spine.server.procman.CommandRouter in project core-java by SpineEventEngine.
the class CommandRouterOnErrorShould method createRouter.
/**
* Creates a router with mocked {@code CommandBus} which always calls
* {@link StreamObserver#onError(Throwable) StreamObserver.onError()} when
* {@link CommandBus#post(Command, StreamObserver) CommandBus.post()} is invoked.
*/
@Override
CommandRouter createRouter(CommandBus ignored, Message sourceMessage, CommandContext commandContext) {
final CommandBus mockBus = mock(CommandBus.class);
doAnswer(new Answer() {
// is OK for Answer
@SuppressWarnings("ReturnOfNull")
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
final StreamObserver<Response> observer = invocation.getArgument(1);
observer.onError(new RuntimeException("simulate error"));
return null;
}
}).when(mockBus).post(any(Command.class), ArgumentMatchers.<StreamObserver<Response>>any());
return new CommandRouter(mockBus, sourceMessage, commandContext);
}
Aggregations