DefaultInterceptorChainProcessor implements InterceptorChainProcessor { @Override public Optional<JsonEnvelope> process(final InterceptorContext interceptorContext) { interceptorContext.setInputParameter("component", component); return new DefaultInterceptorChain(interceptorCache.getInterceptors(component), targetOf(dispatch)) .processNext(interceptorContext) .outputEnvelope(); } DefaultInterceptorChainProcessor(final InterceptorCache interceptorCache, final Function<JsonEnvelope, JsonEnvelope> dispatch, final String component); @Override Optional<JsonEnvelope> process(final InterceptorContext interceptorContext);  }
@Test public void shouldProcessInterceptorContext() throws Exception { final JsonEnvelope inputEnvelope = mock(JsonEnvelope.class); final JsonEnvelope outputEnvelope = mock(JsonEnvelope.class); final InterceptorContext interceptorContext = interceptorContextWithInput(inputEnvelope); final String component = "component"; when(interceptorCache.getInterceptors(component)).thenReturn(interceptors()); when(dispatch.apply(inputEnvelope)).thenReturn(outputEnvelope); final DefaultInterceptorChainProcessor interceptorChainProcessor = new DefaultInterceptorChainProcessor(interceptorCache, dispatch, component); final Optional<JsonEnvelope> result = interceptorChainProcessor.process(interceptorContext); assertThat(result.isPresent(), is(true)); assertThat(result.get(), is(outputEnvelope)); }
@Test public void shouldProcessesDispatcherThatReturnsNull() throws Exception { final JsonEnvelope inputEnvelope = mock(JsonEnvelope.class); final JsonEnvelope outputEnvelope = mock(JsonEnvelope.class); final InterceptorContext interceptorContext = interceptorContextWithInput(inputEnvelope); final String component = "component"; when(interceptorCache.getInterceptors(component)).thenReturn(interceptors()); when(dispatch.apply(inputEnvelope)).thenReturn(null); final DefaultInterceptorChainProcessor interceptorChainProcessor = new DefaultInterceptorChainProcessor(interceptorCache, dispatch, component); final Optional<JsonEnvelope> result = interceptorChainProcessor.process(interceptorContext); assertThat(result, is(Optional.empty())); }