From b64a40f6f4f11c517c95dcdde684d3dec55a0f44 Mon Sep 17 00:00:00 2001 From: macasari Date: Wed, 22 Nov 2023 10:40:38 +0100 Subject: [PATCH] BAEL-6600 - fix various reported issues --- .../baeldung/map/HashMapWithMaxSizeLimit.java | 3 --- ...itMaxSizeHashMapByLinkedHashMapUnitTest.java | 17 ++++++----------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/HashMapWithMaxSizeLimit.java b/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/HashMapWithMaxSizeLimit.java index 517dac6362..63736e49f3 100644 --- a/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/HashMapWithMaxSizeLimit.java +++ b/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/HashMapWithMaxSizeLimit.java @@ -3,9 +3,6 @@ package com.baeldung.map; import java.util.HashMap; public class HashMapWithMaxSizeLimit extends HashMap { - - private static final long serialVersionUID = 1L; - private int maxSize = -1; public HashMapWithMaxSizeLimit() { diff --git a/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/LimitMaxSizeHashMapByLinkedHashMapUnitTest.java b/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/LimitMaxSizeHashMapByLinkedHashMapUnitTest.java index 0986f426d9..d32d98da3a 100644 --- a/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/LimitMaxSizeHashMapByLinkedHashMapUnitTest.java +++ b/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/LimitMaxSizeHashMapByLinkedHashMapUnitTest.java @@ -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 linkedHashMap; - - @BeforeEach - void setUp() { + @Test + void givenLinkedHashMapObject_whenAddingNewEntry_thenEldestEntryIsRemoved() { + final int MAX_SIZE = 4; + LinkedHashMap linkedHashMap; linkedHashMap = new LinkedHashMap() { private static final long serialVersionUID = 1L; - + + @Override protected boolean removeEldestEntry(Map.Entry 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()