### Question:
CveSearchJsonParser implements Function<BufferedReader, T> { @Override public T apply(BufferedReader json) { return gson.fromJson(json,getType()); } CveSearchJsonParser(); abstract Type getType(); @Override T apply(BufferedReader json);  }### Answer:
@Test public void singleEmpty() { cveSearchJsonParserSingle.apply(toBufferedReader(SEARCH_RESULT_EMPTY)); }
@Test public void singleEmptyObj() { cveSearchJsonParserSingle.apply(toBufferedReader(SEARCH_RESULT_EMPTYOBJ)); }
@Test public void testDateParser2_1(){ String date = "2011-03-07T21:50:16.563-05:00"; String json = "{\"Modified\": \"" + date + "\"}"; CveSearchData result = cveSearchJsonParserSingle.apply(toBufferedReader(json)); assert(result.getModified() != null); assert(result.getModified().length()>0); assert(date.equals(result.getModified())); }
@Test public void testDateParser2_2(){ long dateAsLong = 1299534616563L; String json = "{\"Modified\": { \"$date\": " + dateAsLong + "}}"; CveSearchData result = cveSearchJsonParserSingle.apply(toBufferedReader(json)); assert(result.getModified() != null); assert(result.getModified().length()>0); assert(result.getModified().startsWith("2011-03-07T")); }
@Test public void singleFull_A() { CveSearchData result = cveSearchJsonParserSingle.apply(toBufferedReader(SEARCH_RESULT_SINGLE_A)); assert(result.getCvss() == 5.0); assert("CVE-2002-0438".equals(result.getId())); Optional<Map.Entry<String, String>> vce = result.getVulnerable_configuration() .entrySet() .stream() .findAny(); assert(vce.isPresent()); assert(vce.get().getKey().length() > 2); assert(vce.get().getValue().length() > 2); }
@Test public void singleFull_B() { CveSearchData result = cveSearchJsonParserSingle.apply(toBufferedReader(SEARCH_RESULT_SINGLE_B)); assert(result.getCvss() == 5.0); assert("CVE-2002-0438".equals(result.getId())); assert(result.getVulnerable_configuration().size() == 6); Optional<Map.Entry<String, String>> vce = result.getVulnerable_configuration() .entrySet() .stream() .findAny(); assert(vce.isPresent()); assert(vce.get().getKey().length() > 2); assert(vce.get().getValue().length() > 2); assert(! vce.get().getKey().equals(vce.get().getValue())); }
@Test public void listEmpty() { List<CveSearchData> result = cveSearchJsonParserList.apply(toBufferedReader(SEARCH_RESULT_EMPTY)); assert(result==null); }
@Test public void listEmptyList() { List<CveSearchData> result = cveSearchJsonParserList.apply(toBufferedReader(SEARCH_RESULT_EMPTYLIST)); assert(result.size()==0); }
@Test public void listSingletonList() { List<CveSearchData> result = cveSearchJsonParserList.apply(toBufferedReader("[" + SEARCH_RESULT_SINGLE_A + "]")); assert(result.size()==1); }
@Test public void listFullList() { List<CveSearchData> result = cveSearchJsonParserList.apply(toBufferedReader(SEARCH_RESULT_FULL)); assert(result.size()==3); }