### Question:
JSONHelper { public static String getJsonString(Record[] records) throws Exception { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false); StringBuffer buffer = new StringBuffer(); buffer.append('['); for (Iterator<Record> iterator = Arrays.asList(records).iterator(); iterator.hasNext();) { buffer.append(objectMapper.writeValueAsString(toMap(iterator.next()))); if (iterator.hasNext()) { buffer.append(','); } } buffer.append(']'); return buffer.toString(); }  static String getJsonString(Record[] records);  }### Answer:
@Test public void test_getJsonString_EmptyArrayWhenNoRecord() throws Exception { Record[] records = {}; String actualResult = JSONHelper.getJsonString(records); assertEquals("[]", actualResult); }
@Test public void test_getJsonString_AddedRecordWithNoAttributes() throws Exception { Record[] records = { new Record() }; String actualResult = JSONHelper.getJsonString(records); assertEquals("[{}]", actualResult); }
@Test public void test_getJsonString_AddedRecordWithTestAttribute() throws Exception { Record record = new Record(); record.setAttribute("testAttribute", "testAttributeValue"); Record[] records = { record }; String actualResult = JSONHelper.getJsonString(records); assertEquals("[{\"testAttribute\":\"testAttributeValue\"}]", actualResult); }
@Test public void test_getJsonString_AddedManyRecordsWithNoAttributes() throws Exception { Record[] records = { new Record(), new Record() }; String actualResult = JSONHelper.getJsonString(records); assertEquals("[{},{}]", actualResult); }
@Test public void test_getJsonString_AddedManyRecordsWithTestAttributes() throws Exception { Record record1 = new Record(); record1.setAttribute("testAttribute1", "testAttributeValue1"); Record record2 = new Record(); record2.setAttribute("testAttribute2", "testAttributeValue2"); Record[] records = { record1, record2 }; String actualResult = JSONHelper.getJsonString(records); assertEquals("[{\"testAttribute1\":\"testAttributeValue1\"},{\"testAttribute2\":\"testAttributeValue2\"}]", actualResult); }