SkipReceiverExceptionHandler extends ExceptionHandlingReceiver { @Override public void receive(final IMessageProcessor processor) throws MessageReceiveException { IObject context = processor.getContext(); try { processor.getSequence().goTo(getCauseLevel(context), getCauseStep(context) + 1); } catch (ReadValueException | InvalidArgumentException e) { throw new MessageReceiveException("Exception occurred while skipping a receiver thrown exception", e); } } SkipReceiverExceptionHandler(); @Override void receive(final IMessageProcessor processor);  }
@Test public void Should_SkipTheReceiverThrownAnException() throws Exception { IMessageProcessingSequence sequenceMock = mock(IMessageProcessingSequence.class); when(messageProcessorMock.getSequence()).thenReturn(sequenceMock); when(contextMock.getValue(same(causeLevelFieldName))).thenReturn(137); when(contextMock.getValue(same(causeStepFieldName))).thenReturn(123); IMessageReceiver receiver = new SkipReceiverExceptionHandler(); receiver.receive(messageProcessorMock); verify(sequenceMock).goTo(eq(137), eq(124)); }
@Test public void Should_WrapCaughtExceptions() throws Exception { IMessageProcessingSequence sequenceMock = mock(IMessageProcessingSequence.class); Exception exception = new ReadValueException(); when(messageProcessorMock.getSequence()).thenReturn(sequenceMock); when(contextMock.getValue(same(causeLevelFieldName))).thenThrow(exception); when(contextMock.getValue(same(causeStepFieldName))).thenReturn(123); IMessageReceiver receiver = new SkipReceiverExceptionHandler(); try { receiver.receive(messageProcessorMock); fail(); } catch (MessageReceiveException e) { assertSame(exception, e.getCause()); } }