### Question:
JsonRestSourceHandler implements RestSourceHandler { @Override public List<Event> getEvents(String body, Map<String, String> headers) { List<Event> events = new ArrayList<Event>(0); ObjectMapper mapper = new ObjectMapper(); try { JsonNode jsonNode = mapper.readTree(body); if (jsonNode.isObject()) { events.add(buildSingleEvent(headers, findValue(jsonNode, path))); } if (jsonNode.isArray()) { final Iterator<JsonNode> elements = jsonNode.getElements(); JsonNode element; while (elements.hasNext()) { element = elements.next(); events.add(buildSingleEvent(headers, findValue(element, path))); } } } catch (Exception e) { LOG.warn("An error ocurred while response parsing. Then content is not valid: " + body); } return events; } JsonRestSourceHandler(); @Override List<Event> getEvents(String body, Map<String, String> headers); @Override void configure(Context context);  }### Answer:
@Test public void getEventsFromEmptyJson() throws Exception { final List<Event> events = jsonHandler .getEvents("{}", ImmutableMap.<String, String>builder().build()); assertThat(events).isNotEmpty().hasSize(1); assertThat(new String(events.get(0).getBody())).isEqualTo("{}"); }
@Test public void getEventsFromNotValidJson() throws Exception { final List<Event> events = jsonHandler .getEvents("[{\"field1\":\"value1\"},{\"field2\":}]", ImmutableMap.<String, String>builder().build()); assertThat(events).isEmpty(); }
@Test public void getEventsWithDefaultPath() throws Exception { final List<Event> events = jsonHandler .getEvents("[{\"field1\":\"value1\"},{\"field2\":\"value2\"}]", ImmutableMap.<String, String>builder().build()); assertThat(events).isNotEmpty().hasSize(2); }