SearchResultJsonParser implements JsonParser<SearchResult> { @Override public SearchResult parse(JSONObject json) throws JSONException { final int startAt = json.getInt("startAt"); final int maxResults = json.getInt("maxResults"); final int total = json.getInt("total"); final Collection<BasicIssue> issues = JsonParseUtil.parseJsonArray(json.getJSONArray("issues"), basicIssueJsonParser); return new SearchResult(startAt, maxResults, total, issues); }  @Override SearchResult parse(JSONObject json);  }
@Test public void testParse() throws Exception { final SearchResult searchResult = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/search/issues1.json")); final ArrayList<BasicIssue> issues = Lists.newArrayList(new BasicIssue(toUri("http: assertEquals(new SearchResult(0, 50, 1, issues), searchResult); }
@Test public void testParseMany() throws Exception { final SearchResult searchResult = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/search/many-issues.json")); assertEquals(9, searchResult.getTotal()); assertEquals(8, searchResult.getMaxResults()); assertEquals(0, searchResult.getStartIndex()); assertEquals(8, Iterables.size(searchResult.getIssues())); assertEquals(new BasicIssue(toUri("http: }
@Test public void testParseInvalidTotal() throws Exception { exception.expect(JSONException.class); exception.expectMessage("JSONObject[\"total\"] is not a number."); parser.parse(ResourceUtil.getJsonObjectFromResource("/json/search/issues-invalid-total.json")); }