Response { public boolean success() { switch (status) { case 200: case 201: case 202: case 203: case 204: case 205: case 206: return true; default: return false; } } Response(int status, String text, Map<String, List<String>> headers); int getStatus(); String getText(); Map<String, List<String>> getHeaders(); boolean success(); Optional<Object> decodeJson(); Stream<Object> decodeJsonArray();  }
@TestFactory Stream<DynamicTest> success() { final Stream<DynamicTest> successful = IntStream.range(200, 207) .mapToObj(status -> new Response(status, "{}", new HashMap<>())) .map(response -> dynamicTest( format("testing status '%s'", response.getStatus()), () -> assertTrue(response.success()))); final Stream<DynamicTest> unsuccessful = IntStream.range(400, 419) .mapToObj(status -> new Response(status, "{}", new HashMap<>())) .map(response -> dynamicTest( format("testing status '%s'", response.getStatus()), () -> assertFalse(response.success()) )); return Stream.concat(successful, unsuccessful); }