BAEL-6600 - fix various reported issues

This commit is contained in:
macasari 2023-11-22 10:40:38 +01:00
parent b38867d054
commit b64a40f6f4
2 changed files with 6 additions and 14 deletions

View File

@ -3,9 +3,6 @@ package com.baeldung.map;
import java.util.HashMap; import java.util.HashMap;
public class HashMapWithMaxSizeLimit<K, V> extends HashMap<K, V> { public class HashMapWithMaxSizeLimit<K, V> extends HashMap<K, V> {
private static final long serialVersionUID = 1L;
private int maxSize = -1; private int maxSize = -1;
public HashMapWithMaxSizeLimit() { public HashMapWithMaxSizeLimit() {

View File

@ -5,19 +5,18 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
class LimitMaxSizeHashMapByLinkedHashMapUnitTest { class LimitMaxSizeHashMapByLinkedHashMapUnitTest {
private final int MAX_SIZE = 4; @Test
private LinkedHashMap<Integer, String> linkedHashMap; void givenLinkedHashMapObject_whenAddingNewEntry_thenEldestEntryIsRemoved() {
final int MAX_SIZE = 4;
@BeforeEach LinkedHashMap<Integer, String> linkedHashMap;
void setUp() {
linkedHashMap = new LinkedHashMap<Integer, String>() { linkedHashMap = new LinkedHashMap<Integer, String>() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override
protected boolean removeEldestEntry(Map.Entry<Integer, String> eldest) { protected boolean removeEldestEntry(Map.Entry<Integer, String> eldest) {
return size() > MAX_SIZE; return size() > MAX_SIZE;
} }
@ -26,10 +25,6 @@ class LimitMaxSizeHashMapByLinkedHashMapUnitTest {
linkedHashMap.put(2, "Two"); linkedHashMap.put(2, "Two");
linkedHashMap.put(3, "Three"); linkedHashMap.put(3, "Three");
linkedHashMap.put(4, "Four"); linkedHashMap.put(4, "Four");
}
@Test
void givenLinkedHashMapObject_whenAddingNewEntry_thenEldestEntryIsRemoved() {
linkedHashMap.put(5, "Five"); linkedHashMap.put(5, "Five");
String[] expectedArrayAfterFive = { "Two", "Three", "Four", "Five" }; String[] expectedArrayAfterFive = { "Two", "Three", "Four", "Five" };
assertArrayEquals(expectedArrayAfterFive, linkedHashMap.values() assertArrayEquals(expectedArrayAfterFive, linkedHashMap.values()