HttpUtils { public static boolean isSuccessStatus(int status) { return status >= HttpConstants.STATUS_OK && status < 300; } private  HttpUtils(); static T waitFor(Future<? extends T> future); static Throwable unwrapCompletionException(Throwable ex); static boolean isSuccessStatus(int status); static ResponseProcessor<T> checkResponse(ResponseProcessor<T> processor,
                                                         Predicate<Response> successPredicate,
                                                         String tag); static ResponseProcessor<T> checkResponse(ResponseProcessor<T> processor,
                                                         Predicate<Response> successPredicate); static ResponseProcessor<T> checkResponse(ResponseProcessor<T> processor, String tag); static ResponseProcessor<T> checkResponse(ResponseProcessor<T> processor); static Predicate<Response> hasStatus(int status); static FailedRequestException createExceptionForResponse(Response response, String tag); static ResponseProcessor<T> jsonResult(ObjectMapper mapper, Class<T> resultClass); static ResponseProcessor<T> jsonResult(ObjectMapper mapper, TypeReference<T> typeReference); static Consumer<RequestBuilder> get(String uri); static ResponseProcessor<T> nullProcessor(); static String urlEncode(String src); static String addQueryParameters(String url, Map<String, ?> params); static String addQueryParameters(String url, Map<String, ?> params, boolean filterUndefined); static String addQueryParameter(String url, String key, Object value); static final Predicate<Response> SUCCESS_STATUS; }
@Test public void testIsSuccessStatusTooSmall() { assertThat(HttpUtils.isSuccessStatus(199)).isFalse(); assertThat(HttpUtils.isSuccessStatus(0)).isFalse(); assertThat(HttpUtils.isSuccessStatus(Integer.MIN_VALUE)).isFalse(); }
@Test public void testIsSuccessStatusTrue() { for (int i = 200; i < 300; i++) { assertThat(HttpUtils.isSuccessStatus(i)).isTrue(); } }
@Test public void testIsSuccessStatusTooBig() { assertThat(HttpUtils.isSuccessStatus(300)).isFalse(); assertThat(HttpUtils.isSuccessStatus(HttpConstants.STATUS_ERR_BAD_REQUEST)).isFalse(); assertThat(HttpUtils.isSuccessStatus(HttpConstants.STATUS_ERR_SERVER)).isFalse(); assertThat(HttpUtils.isSuccessStatus(Integer.MAX_VALUE)).isFalse(); }