diff --git a/java-collections-maps-3/pom.xml b/java-collections-maps-3/pom.xml index 81466b17ba..a54061404d 100644 --- a/java-collections-maps-3/pom.xml +++ b/java-collections-maps-3/pom.xml @@ -16,6 +16,13 @@ + + + org.junit.jupiter + junit-jupiter-api + 5.8.1 + + org.springframework spring-core diff --git a/java-collections-maps-3/src/main/java/com/baeldung/map/identity/IdentityHashMapDemonstrator.java b/java-collections-maps-3/src/main/java/com/baeldung/map/identity/IdentityHashMapDemonstrator.java index dbd309eab3..faba9f60f8 100644 --- a/java-collections-maps-3/src/main/java/com/baeldung/map/identity/IdentityHashMapDemonstrator.java +++ b/java-collections-maps-3/src/main/java/com/baeldung/map/identity/IdentityHashMapDemonstrator.java @@ -1,6 +1,7 @@ package com.baeldung.map.identity; import java.util.*; +import static org.junit.jupiter.api.Assertions.assertEquals; public class IdentityHashMapDemonstrator { public static void main(String[] args) { @@ -22,8 +23,8 @@ public class IdentityHashMapDemonstrator { IdentityHashMap identityHashMap = new IdentityHashMap<>(); identityHashMap.put(null, "Null Key Accepted"); identityHashMap.put("Null Value Accepted", null); - assert ("Null Key Accepted" == identityHashMap.get(null)); - assert (null == identityHashMap.get("Null Value Accepted")); + assertEquals("Null Key Accepted", identityHashMap.get(null)); + assertEquals(null, identityHashMap.get("Null Value Accepted")); } private static void iterateIdentityHashMap(IdentityHashMap identityHashMap) { @@ -95,14 +96,14 @@ public class IdentityHashMapDemonstrator { hashMap.put(book1, "A great work of fiction"); hashMap.put(book2, "won the US National Book Award"); book2.year = 1952; - assert (null == hashMap.get(book2)); + assertEquals(null, hashMap.get(book2)); System.out.println("HashMap: " + hashMap); IdentityHashMap identityHashMap = new IdentityHashMap<>(10); identityHashMap.put(book1, "A great work of fiction"); identityHashMap.put(book2, "won the US National Book Award"); book2.year = 1951; - assert ("won the US National Book Award" == identityHashMap.get(book2)); + assertEquals("won the US National Book Award", identityHashMap.get(book2)); System.out.println("IdentityHashMap: " + identityHashMap); } @@ -115,11 +116,11 @@ public class IdentityHashMapDemonstrator { HashMap hashMap = new HashMap<>(identityHashMap); hashMap.put(new String("genre"), "Drama"); - assert (4 == hashMap.size()); + assertEquals(4, hashMap.size()); System.out.println("HashMap content: " + hashMap); identityHashMap.put(new String("genre"), "Drama"); - assert (5 == identityHashMap.size()); + assertEquals(5, identityHashMap.size()); System.out.println("IdentityHashMap content: " + identityHashMap); } @@ -135,8 +136,8 @@ public class IdentityHashMapDemonstrator { private static void updateWithNewValue(IdentityHashMap identityHashMap) { String oldTitle = identityHashMap.put("title", "Harry Potter and the Deathly Hallows"); - assert ("Harry Potter and the Goblet of Fire" == oldTitle); - assert ("Harry Potter and the Deathly Hallows" == identityHashMap.get("title")); + assertEquals("Harry Potter and the Goblet of Fire", oldTitle); + assertEquals("Harry Potter and the Deathly Hallows", identityHashMap.get("title")); } public static void addValue(IdentityHashMap identityHashMap, String key, String value) {