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;
public class HashMapWithMaxSizeLimit<K, V> extends HashMap<K, V> {
private static final long serialVersionUID = 1L;
private int maxSize = -1;
public HashMapWithMaxSizeLimit() {

View File

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