BAEL-6978: Adding the information about the bug (#14804)

This commit is contained in:
Eugene Kovko 2023-09-21 19:26:51 +02:00 committed by GitHub
parent e64dbf88ac
commit f2b6460056
2 changed files with 44 additions and 1 deletions

View File

@ -53,7 +53,7 @@ public class IdentityHashMapDemonstrator {
}
}
private static class Book {
static class Book {
String title;
int year;

View File

@ -1,8 +1,11 @@
package com.baeldung.map.identity;
import com.baeldung.map.identity.IdentityHashMapDemonstrator.Book;
import org.junit.jupiter.api.Test;
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;
@ -18,4 +21,44 @@ public class IdentityHashMapDemonstratorUnitTest {
assertEquals("Fantasy", identityHashMap.get("genre"));
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));
}
}