@Test public void addContributedHandlers() throws Exception { final AttributesMap attributes = new AttributesMap(); final Request request = mock(Request.class); final Context context = mock(Context.class); when(context.getRequest()).thenReturn(request); when(context.getAttributes()).thenReturn(attributes); when(context.proceed()).thenReturn(HttpResponses.ok(new Content(new StringPayload("test", "text/plain")))); final ContributedHandler handlerA = mock(ContributedHandler.class); final ContributedHandler handlerB = mock(ContributedHandler.class); final HandlerContributor underTest = new HandlerContributor(asList(handlerA, handlerB)); final Response response = underTest.handle(context); assertThat(response.getStatus().isSuccessful(), is(true)); assertThat(attributes.get(HandlerContributor.EXTENDED_MARKER), is(Boolean.TRUE)); underTest.handle(context); ArgumentCaptor<ContributedHandler> handlerCaptor = ArgumentCaptor.forClass(ContributedHandler.class); verify(context, times(2)).insertHandler(handlerCaptor.capture()); assertThat(handlerCaptor.getAllValues(), is(asList(handlerB, handlerA))); }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { if (!isMarkedExtended(context)) { ListIterator<ContributedHandler> handlerIterator = contributedHandlers.listIterator(contributedHandlers.size()); while (handlerIterator.hasPrevious()) { context.insertHandler(handlerIterator.previous()); } markExtended(context); } return context.proceed(); }
HandlerContributor implements Handler { @Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { if (!isMarkedExtended(context)) { ListIterator<ContributedHandler> handlerIterator = contributedHandlers.listIterator(contributedHandlers.size()); while (handlerIterator.hasPrevious()) { context.insertHandler(handlerIterator.previous()); } markExtended(context); } return context.proceed(); } }
HandlerContributor implements Handler { @Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { if (!isMarkedExtended(context)) { ListIterator<ContributedHandler> handlerIterator = contributedHandlers.listIterator(contributedHandlers.size()); while (handlerIterator.hasPrevious()) { context.insertHandler(handlerIterator.previous()); } markExtended(context); } return context.proceed(); } @Inject  HandlerContributor(final List<ContributedHandler> contributedHandlers); }
HandlerContributor implements Handler { @Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { if (!isMarkedExtended(context)) { ListIterator<ContributedHandler> handlerIterator = contributedHandlers.listIterator(contributedHandlers.size()); while (handlerIterator.hasPrevious()) { context.insertHandler(handlerIterator.previous()); } markExtended(context); } return context.proceed(); } @Inject  HandlerContributor(final List<ContributedHandler> contributedHandlers); @Nonnull @Override Response handle(@Nonnull final Context context); }
HandlerContributor implements Handler { @Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { if (!isMarkedExtended(context)) { ListIterator<ContributedHandler> handlerIterator = contributedHandlers.listIterator(contributedHandlers.size()); while (handlerIterator.hasPrevious()) { context.insertHandler(handlerIterator.previous()); } markExtended(context); } return context.proceed(); } @Inject  HandlerContributor(final List<ContributedHandler> contributedHandlers); @Nonnull @Override Response handle(@Nonnull final Context context);  }