JsonHttpUtil { public static <REQUEST_T, RESPONSE_T> RESPONSE_T postOne(String url, REQUEST_T requestBodyObject, Class<RESPONSE_T> responseType) throws Exception { String requestBodyStr = JsonUtil.toJson(requestBodyObject); String responseStr = HttpUtil.post(url, requestBodyStr); return JsonUtil.toBean(responseStr, responseType); }  static RESPONSE_T postOne(String url, REQUEST_T requestBodyObject, Class<RESPONSE_T> responseType); static RESPONSE_T postOne(String url, Class<RESPONSE_T> responseType); static RESPONSE_T postCollection(String url, REQUEST_T requestBodyObject, TypeReference<RESPONSE_T> typeReference); static RESPONSE_T postCollection(String url, TypeReference<RESPONSE_T> typeReference); static RESPONSE_T getOne(String url, Class<RESPONSE_T> responseType); static RESPONSE_T getCollection(String url, TypeReference<RESPONSE_T> typeReference);  }
@Test public void testPostOne() throws Exception { String url = buildUrl("postOne"); User user = JsonHttpUtil.postOne(url, User.class); Assert.hasLength(user.getName()); }
@Test public void testPostOneWithRequestBody() throws Exception { String url = buildUrl("postOneWithRequestBody"); User user = JsonHttpUtil.postOne(url, USER, User.class); Assert.hasLength(user.getName()); }