### Question:
PipelineToJSONConverter { public static List<JSONObject> getFields(List<Object> pipelineData, String rootId) { List<JSONObject> records = new ArrayList<>(); if(pipelineData == null) { logger.log(Level.INFO,"Input data is empty for transformation."); return records; } for (Object data : pipelineData) { try { String stringData = (String) data; records.add((JSONObject) ((JSONObject) parser.parse(stringData)).get(rootId)); } catch (Exception ex) { logger.severe("Error while parsing data: " + data + " to JSON object."); } } return records; }  static List<JSONObject> getFields(List<Object> pipelineData, String rootId);  }### Answer:
@Test public void TestConversionForEmptyPipelineData() { List<JSONObject> jsonData = PipelineToJSONConverter.getFields(null, ROOT_ID); assert (jsonData.size() == 0); }
@Test public void TestConversionForCorruptPipelineData() { List<Object> badData = new ArrayList<>(); badData.add("{ bad JSon String"); List<JSONObject> jsonData = PipelineToJSONConverter.getFields(badData, ROOT_ID); assert (jsonData.size() == 0); }
@Test public void TestPipelineDataToJsonConversion() { List<JSONObject> jsonData = PipelineToJSONConverter.getFields(pipelineData, ROOT_ID); assert (jsonData.size() == 2); JSONObject row1 = jsonData.get(0); Set<String> firstKeySet = row1.keySet(); assert (firstKeySet.contains("key1_1")); assert (firstKeySet.contains("key1_2")); JSONObject row2 = jsonData.get(1); Set<String> secondKeySet = row2.keySet(); assert (secondKeySet.contains("key2_1")); assert (secondKeySet.contains("key2_2")); }