ProblemRoute { public static Route problemHandling() { return PROPAGATE; } private  ProblemRoute(); static Route problemHandling(); static Route problemHandling(final ThrowingConsumer<Exceptional, ? extends Exception> consumer); static Route problemHandling(final Route fallback); static Route problemHandling(final ThrowingConsumer<Exceptional, ? extends Exception> consumer,
            final Route fallback);  }
@Test void shouldDelegateProblemHandling() { server.expect(requestTo(url)) .andRespond(withStatus(BAD_REQUEST) .body(new ClassPathResource("problem.json")) .contentType(MediaType.parseMediaType("application/problem+json"))); unit.get(url) .dispatch(series(), on(SUCCESSFUL).call(pass()), anySeries().call(problemHandling(consumer))) .join(); verify(consumer).tryAccept(any()); }
@Test void shouldUseFallback() throws Exception { server.expect(requestTo(url)) .andRespond(withStatus(BAD_REQUEST) .body("Error!")); unit.get(url) .dispatch(series(), on(SUCCESSFUL).call(pass()), anySeries().call(problemHandling(fallback))) .join(); verify(fallback).execute(any(), any()); }
@Test void shouldNotDelegateProblemHandlingAndUseFallback() throws Exception { server.expect(requestTo(url)) .andRespond(withStatus(BAD_REQUEST) .body("Error!")); unit.get(url) .dispatch(series(), on(SUCCESSFUL).call(pass()), anySeries().call(problemHandling(consumer, fallback))) .join(); verifyZeroInteractions(consumer); verify(fallback).execute(any(), any()); }
@Test void shouldDelegateProblemHandlingAndNotUseFallback() { server.expect(requestTo(url)) .andRespond(withStatus(BAD_REQUEST) .body(new ClassPathResource("problem.json")) .contentType(MediaType.parseMediaType("application/problem+json"))); unit.get(url) .dispatch(series(), on(SUCCESSFUL).call(pass()), anySeries().call(problemHandling(consumer, fallback))) .join(); verify(consumer).tryAccept(any()); verifyZeroInteractions(fallback); }