AbstractJerseyRestClient { static Collection<String> extractErrors(String body) throws JSONException { JSONObject jsonObject = new JSONObject(body); final Collection<String> errorMessages = new ArrayList<String>(); final JSONArray errorMessagesJsonArray = jsonObject.optJSONArray("errorMessages"); if (errorMessagesJsonArray != null) { errorMessages.addAll(JsonParseUtil.toStringCollection(errorMessagesJsonArray)); } final JSONObject errorJsonObject = jsonObject.optJSONObject("errors"); if (errorJsonObject != null) { final JSONArray valuesJsonArray = errorJsonObject.toJSONArray(errorJsonObject.names()); if (valuesJsonArray != null) { errorMessages.addAll(JsonParseUtil.toStringCollection(valuesJsonArray)); } } return errorMessages; } AbstractJerseyRestClient(URI baseUri, ApacheHttpClient client);   }
@Test public void testExtractErrors() throws JSONException { final String str = ResourceUtil.getStringFromResource("/json/error/valid.json"); final Collection<String> stringCollection = AbstractJerseyRestClient.extractErrors(str); Assert.assertThat(stringCollection, IterableMatcher.hasOnlyElements("abcfsd")); }
@Test public void testExtractErrors2() throws JSONException { final String str = ResourceUtil.getStringFromResource("/json/error/valid2.json"); final Collection<String> stringCollection = AbstractJerseyRestClient.extractErrors(str); Assert.assertThat(stringCollection, IterableMatcher.hasOnlyElements("a", "b", "xxx")); }
@Test public void testExtractErrors3() throws JSONException { final String str = ResourceUtil.getStringFromResource("/json/error/valid3.json"); final Collection<String> stringCollection = AbstractJerseyRestClient.extractErrors(str); Assert.assertThat(stringCollection, IterableMatcher.hasOnlyElements("aa", "bb")); }
@Test public void testExtractErrors4() throws JSONException { final String str = ResourceUtil.getStringFromResource("/json/error/valid4.json"); final Collection<String> stringCollection = AbstractJerseyRestClient.extractErrors(str); Assert.assertThat(stringCollection, IterableMatcher.hasOnlyElements("a", "b", "y", "z")); }