/*
 * Copyright 2017, TeamDev Ltd. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.spine3.server.procman;

import com.google.protobuf.Message;
import org.spine3.base.CommandContext;
import org.spine3.server.command.CommandBus;

/**
 * @author Alexaneder Yevsyukov
 */
public class CommandRouterOnErrorShould extends AbstractCommandRouterShould<CommandRouter> {

    @Override
    CommandRouter createRouter(CommandBus commandBus, Message sourceMessage, CommandContext commandContext) {
        return new CommandRouter(commandBus, sourceMessage, commandContext);
    }

}

@@ -1093,83 +1093,461 @@
 ort 
-org.spine3.base.CommandContext;%0Aimport org.spine3.server.command.CommandBus
+io.grpc.stub.StreamObserver;%0Aimport org.junit.Test;%0Aimport org.mockito.ArgumentMatchers;%0Aimport org.mockito.invocation.InvocationOnMock;%0Aimport org.mockito.stubbing.Answer;%0Aimport org.spine3.base.Command;%0Aimport org.spine3.base.CommandContext;%0Aimport org.spine3.base.Response;%0Aimport org.spine3.server.command.CommandBus;%0A%0Aimport static org.mockito.ArgumentMatchers.any;%0Aimport static org.mockito.Mockito.doAnswer;%0Aimport static org.mockito.Mockito.mock
 ;%0A%0A/
@@ -1735,26 +1735,23 @@
 mandBus 
-commandBus
+ignored
 , Messag
@@ -1812,82 +1812,808 @@
     
-return new CommandRouter(commandBus, sourceMessage, commandContext);%0A    %7D%0A
+final CommandBus mockBus = mock(CommandBus.class);%0A%0A        doAnswer(new Answer() %7B%0A            @SuppressWarnings(%22ReturnOfNull%22) // is OK for Answer%0A            @Override%0A            public Object answer(InvocationOnMock invocation) throws Throwable %7B%0A                final StreamObserver%3CResponse%3E observer = invocation.getArgument(1);%0A                observer.onError(new RuntimeException(%22simulate error%22));%0A                return null;%0A            %7D%0A        %7D).when(mockBus).post(any(Command.class), ArgumentMatchers.%3CStreamObserver%3CResponse%3E%3Eany());%0A%0A        return new CommandRouter(mockBus, sourceMessage, commandContext);%0A    %7D%0A%0A    @Test(expected = IllegalStateException.class)%0A    public void throw_IllegalStateException_when_caught_error_when_posting() %7B%0A        router().routeAll();%0A    %7D
 %0A%7D%0A

Test command router behaviour on error