### Question:
JsonDataSource extends ColumnarDataSource { public RecordIterator getRecordsFromString(String s) { try { JsonFactory jsonFactory = new JsonFactory(); return new JsonIterator(jsonFactory.createParser(new StringReader(s))); } catch (IOException e) { throw new DukeException(e); } } JsonDataSource(); String getInputFile(); void setInputFile(String file); RecordIterator getRecordsFromString(String s); RecordIterator getRecordsFromStream(InputStream is); RecordIterator getRecords(); @Override void writeConfig(ConfigWriter cw); String getSourceName();  }### Answer:
@Test public void testEmpty() throws IOException { RecordIterator it = source.getRecordsFromString(""); assertTrue(!it.hasNext()); }
@Test public void testSingleRecord() throws IOException { Record r = source.getRecordsFromString("{\"F1\":\"a\",\"F2\" : \"b\", \"F3\" : \"c\", \"F4\" : \"d\"}").next(); assertEquals("a", r.getValue("F1")); assertEquals("b", r.getValue("F2")); assertEquals("c", r.getValue("F3")); }
@Test public void testArrayField() { Record r = source.getRecordsFromString("{\"F1\":[\"a\",\"b\",\"c\"]}").next(); assertEquals(3, r.getValues("F1").size()); }
@Test public void testNestRecords() { Record r = source.getRecordsFromString("{\"F1\":\"a\",\"FF2\" : {\"F2\" : \"b\"}, \"FFF3\" : {\"FF3\" : {\"F3\" : \"c\",\"F4\" : \"d\"}}}").next(); assertEquals("a", r.getValue("F1")); assertEquals("b", r.getValue("F2")); assertEquals("c", r.getValue("F3")); }
@Test public void multipleRecords() { RecordIterator it = source.getRecordsFromString("{\"F1\":\"a\",\"F2\" : \"b\", \"F3\" : \"c\"}{\"F1\":\"a2\",\"F2\" : \"b2\", \"F3\" : \"c2\"}"); Record r1 = it.next(); assertEquals("a", r1.getValue("F1")); assertEquals("b", r1.getValue("F2")); assertEquals("c", r1.getValue("F3")); Record r2 = it.next(); assertEquals("a2", r2.getValue("F1")); assertEquals("b2", r2.getValue("F2")); assertEquals("c2", r2.getValue("F3")); }