MessageProcessingSequence implements IMessageProcessingSequence, IDumpable { @Override public void callChain(final IReceiverChain chain) throws NestedChainStackOverflowException { int newStackIndex = stackIndex + 1; if (newStackIndex >= chainStack.length) { throw new NestedChainStackOverflowException( Arrays.copyOf(chainStack, stackIndex + 1), Arrays.copyOf(stepStack, stackIndex + 1)); } chainStack[newStackIndex] = chain; stepStack[newStackIndex] = -1; stackIndex = newStackIndex; } MessageProcessingSequence(final int stackDepth, final IReceiverChain mainChain); @Override void reset(); @Override boolean next(); @Override void goTo(final int level, final int step); @Override void end(); @Override int getCurrentLevel(); @Override int getStepAtLevel(final int level); @Override IMessageReceiver getCurrentReceiver(); @Override IObject getCurrentReceiverArguments(); @Override void callChain(final IReceiverChain chain); @Override void catchException(final Throwable exception, final IObject context); @Override IObject dump(final IObject options);  }
@Test(expected = NestedChainStackOverflowException.class) public void Should_throw_When_stackOverflowOccurs() throws Exception { when(mainChainMock.get(eq(0))).thenReturn(messageReceiverMocks[0]); IMessageProcessingSequence messageProcessingSequence = new MessageProcessingSequence(4, mainChainMock); try { messageProcessingSequence.callChain(mainChainMock); messageProcessingSequence.callChain(mainChainMock); messageProcessingSequence.callChain(mainChainMock); } catch (NestedChainStackOverflowException e) { fail(); } messageProcessingSequence.callChain(mainChainMock); }