StubResponseProcessor { public byte[] processResponse(final HttpServletRequest req, final HttpServletResponse resp, final byte[] responseBody) { byte[] result = responseBody; for (ResponseProcessor processor : responseProcessors) { result = processor.process(req, resp, result); } return result; }  byte[] processResponse(final HttpServletRequest req, final HttpServletResponse resp, final byte[] responseBody); void setResponseProcessors(final List<ResponseProcessor> responseProcessors);  }
@Test public void testProcessResponseShouldReturnWithResponseBodyWhenProcessorListIsEmpty() { processors.clear(); byte[] actual = underTest.processResponse(req, resp, responseBody); assertEquals(actual, responseBody); }
@Test public void testProcessResponseShouldCallProcessorWhenProcessorListIsNotEmpty() { given(processorMock.process(req, resp, responseBody)).willReturn(responseBody); byte[] actual = underTest.processResponse(req, resp, responseBody); verify(processorMock).process(req, resp, responseBody); assertEquals(actual, responseBody); }
@Test public void testProcessResponseShouldCallTwiceProcessorWhenProcessorListContainsTwoProcessor() { processors.add(processorMock); given(processorMock.process(req, resp, responseBody)).willReturn(responseBody); byte[] actual = underTest.processResponse(req, resp, responseBody); verify(processorMock, times(2)).process(req, resp, responseBody); assertEquals(actual, responseBody); }