diff --git a/core-java-modules/core-java-collections-maps-6/src/test/java/com/baeldung/maptojson/MapToJsonUnitTest.java b/core-java-modules/core-java-collections-maps-6/src/test/java/com/baeldung/maptojson/MapToJsonUnitTest.java index d9b13f4f4a..d9c3ac57ff 100644 --- a/core-java-modules/core-java-collections-maps-6/src/test/java/com/baeldung/maptojson/MapToJsonUnitTest.java +++ b/core-java-modules/core-java-collections-maps-6/src/test/java/com/baeldung/maptojson/MapToJsonUnitTest.java @@ -17,40 +17,40 @@ import java.util.HashMap; import java.util.Map; public class MapToJsonUnitTest { -String originalJsonData = "{\"CS\":\"Post1\",\"Linux\":\"Post1\",\"Kotlin\":\"Post1\"}"; + String originalJsonData = "{\"CS\":\"Post1\",\"Linux\":\"Post1\",\"Kotlin\":\"Post1\"}"; -@Test -public void given_HashMapData_whenUsingJackson_thenConvertToJson() throws JsonProcessingException { - Map data = new HashMap(); - data.put("CS", "Post1"); - data.put("Linux", "Post1"); - data.put("Kotlin", "Post1"); - ObjectMapper objectMapper = new ObjectMapper(); - String jacksonData = objectMapper.writeValueAsString(data); - Assertions.assertEquals(jacksonData,originalJsonData); -} + @Test + public void given_HashMapData_whenUsingJackson_thenConvertToJson() throws JsonProcessingException { + Map data = new HashMap(); + data.put("CS", "Post1"); + data.put("Linux", "Post1"); + data.put("Kotlin", "Post1"); + ObjectMapper objectMapper = new ObjectMapper(); + String jacksonData = objectMapper.writeValueAsString(data); + Assertions.assertEquals(originalJsonData,jacksonData); + } -@Test -public void given_HashMapData_whenUsingGson_thenConvertToJson() { - Map data = new HashMap<>(); - data.put("CS", "Post1"); - data.put("Linux", "Post1"); - data.put("Kotlin", "Post1"); - Gson gson = new Gson(); - Type typeObject = new TypeToken() { - }.getType(); - String gsonData = gson.toJson(data, typeObject); - Assertions.assertEquals(gsonData,originalJsonData); -} + @Test + public void given_HashMapData_whenUsingGson_thenConvertToJson() { + Map data = new HashMap<>(); + data.put("CS", "Post1"); + data.put("Linux", "Post1"); + data.put("Kotlin", "Post1"); + Gson gson = new Gson(); + Type typeObject = new TypeToken() { + }.getType(); + String gsonData = gson.toJson(data, typeObject); + Assertions.assertEquals(originalJsonData,gsonData); + } -@Test -public void given_HashMapData_whenOrgJson_thenConvertToJsonUsing() { - Map data = new HashMap<>(); - data.put("CS", "Post1"); - data.put("Linux", "Post1"); - data.put("Kotlin", "Post1"); - JSONObject jsonObject = new JSONObject(data); - String orgJsonData = jsonObject.toString(); - Assertions.assertEquals(orgJsonData,originalJsonData); -} + @Test + public void given_HashMapData_whenOrgJson_thenConvertToJsonUsing() { + Map data = new HashMap<>(); + data.put("CS", "Post1"); + data.put("Linux", "Post1"); + data.put("Kotlin", "Post1"); + JSONObject jsonObject = new JSONObject(data); + String orgJsonData = jsonObject.toString(); + Assertions.assertEquals(originalJsonData,orgJsonData); + } } \ No newline at end of file