BAEL-6978: Adding the information about the bug (#14804)
This commit is contained in:
parent
e64dbf88ac
commit
f2b6460056
@ -53,7 +53,7 @@ public class IdentityHashMapDemonstrator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Book {
|
static class Book {
|
||||||
String title;
|
String title;
|
||||||
int year;
|
int year;
|
||||||
|
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package com.baeldung.map.identity;
|
package com.baeldung.map.identity;
|
||||||
|
|
||||||
|
import com.baeldung.map.identity.IdentityHashMapDemonstrator.Book;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
|
import org.junit.jupiter.api.condition.EnabledForJreRange;
|
||||||
|
import org.junit.jupiter.api.condition.JRE;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
@ -18,4 +21,44 @@ public class IdentityHashMapDemonstratorUnitTest {
|
|||||||
assertEquals("Fantasy", identityHashMap.get("genre"));
|
assertEquals("Fantasy", identityHashMap.get("genre"));
|
||||||
assertEquals("Drama", identityHashMap.get(newGenreKey));
|
assertEquals("Drama", identityHashMap.get(newGenreKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnabledForJreRange(max = JRE.JAVA_19)
|
||||||
|
public void removeEntryComparingValueByEquality() {
|
||||||
|
Book book = new Book("A Passage to India", 1924);
|
||||||
|
IdentityHashMap<Book, String> identityHashMap = new IdentityHashMap<>(10);
|
||||||
|
identityHashMap.put(book, "A great work of fiction");
|
||||||
|
identityHashMap.remove(book, new String("A great work of fiction"));
|
||||||
|
assertEquals(null, identityHashMap.get(book));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnabledForJreRange(max = JRE.JAVA_19)
|
||||||
|
public void replaceEntryComparingValueByEquality() {
|
||||||
|
Book book = new Book("A Passage to India", 1924);
|
||||||
|
IdentityHashMap<Book, String> identityHashMap = new IdentityHashMap<>(10);
|
||||||
|
identityHashMap.put(book, "A great work of fiction");
|
||||||
|
identityHashMap.replace(book, new String("A great work of fiction"), "One of the greatest books");
|
||||||
|
assertEquals("One of the greatest books", identityHashMap.get(book));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnabledForJreRange(min = JRE.JAVA_20)
|
||||||
|
public void dontRemoveEntryComparingValueByEquality() {
|
||||||
|
Book book = new Book("A Passage to India", 1924);
|
||||||
|
IdentityHashMap<Book, String> identityHashMap = new IdentityHashMap<>(10);
|
||||||
|
identityHashMap.put(book, "A great work of fiction");
|
||||||
|
identityHashMap.remove(book, new String("A great work of fiction"));
|
||||||
|
assertEquals("A great work of fiction", identityHashMap.get(book));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnabledForJreRange(min = JRE.JAVA_20)
|
||||||
|
public void dontReplaceEntryComparingValueByEquality() {
|
||||||
|
Book book = new Book("A Passage to India", 1924);
|
||||||
|
IdentityHashMap<Book, String> identityHashMap = new IdentityHashMap<>(10);
|
||||||
|
identityHashMap.put(book, "A great work of fiction");
|
||||||
|
identityHashMap.replace(book, new String("A great work of fiction"), "One of the greatest books");
|
||||||
|
assertEquals("A great work of fiction", identityHashMap.get(book));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user