### Question:
JSONUtil { public Map<String, String> jsonToMap(String jsonStr) { if (jsonStr == null || jsonStr.isEmpty()) { return new HashMap<String, String>(); } ObjectMapper mapper = new ObjectMapper(); try { Map<String, String> tempObject = mapper.readValue(jsonStr, new TypeReference<Map<String, String>>() { }); return tempObject; } catch (JsonParseException e) { throw restErrorUtil.createRESTException( "Invalid input data: " + e.getMessage(), MessageEnums.INVALID_INPUT_DATA); } catch (JsonMappingException e) { throw restErrorUtil.createRESTException( "Invalid input data: " + e.getMessage(), MessageEnums.INVALID_INPUT_DATA); } catch (IOException e) { throw restErrorUtil.createRESTException( "Invalid input data: " + e.getMessage(), MessageEnums.INVALID_INPUT_DATA); } }  File writeJsonToFile(ViewBaseBean viewBean, String fileName); Map<String, String> jsonToMap(String jsonStr); String readMapToString(Map<?, ?> map); String readListToString(List<?> list); String writeObjectAsString(ViewBaseBean vObj);  }### Answer:
@Test public void testJsonToMapNull() { String jsonStr = null; Map<String, String> dbMap = jsonUtil.jsonToMap(jsonStr); Assert.assertEquals(dbMap.get(jsonStr), jsonStr); }
@Test public void testJsonToMapIsEmpty() { String jsonStr = ""; Map<String, String> dbMap = jsonUtil.jsonToMap(jsonStr); boolean isEmpty = dbMap.isEmpty(); Assert.assertTrue(isEmpty); }
@Test public void testJsonToMap() { String jsonStr = "{\"username\":\"admin\",\"password\":\"admin\",\"fs.default.name\":\"defaultnamevalue\",\"hadoop.security.authorization\":\"authvalue\",\"hadoop.security.authentication\":\"authenticationvalue\",\"hadoop.security.auth_to_local\":\"localvalue\",\"dfs.datanode.kerberos.principal\":\"principalvalue\",\"dfs.namenode.kerberos.principal\":\"namenodeprincipalvalue\",\"dfs.secondary.namenode.kerberos.principal\":\"secprincipalvalue\",\"commonNameForCertificate\":\"certificatevalue\"}"; Map<String, String> dbMap = jsonUtil.jsonToMap(jsonStr); Assert.assertNotNull(dbMap); }