Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cd09e52

Browse filesBrowse files
authored
Bael 4464 (eugenp#11062)
* BAEL-4464 : how to implement LRU-Cache in java codes added * BAEL-4464 : how to implement LRU-Cache in java codes added - package named fixed * BAEL-4464 : how to implement LRU-Cache in java codes added - package named changed * BAEL-4464 : how to implement LRU-Cache in java codes added - unitTest fixed * BAEL-4464 : issues 4,5 fixed. * fixed some issues in BAEL-4464 * BAEL-4464 : some tips on unitTest fixed
1 parent 28c9836 commit cd09e52
Copy full SHA for cd09e52

File tree

Expand file treeCollapse file tree

1 file changed

+5
-13
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-13
lines changed
Open diff view settings
Collapse file
+5-13Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
package com.baeldung.lrucache;
22

3-
import com.baeldung.lrucache.Cache;
4-
import com.baeldung.lrucache.LRUCache;
5-
import org.hamcrest.core.AllOf;
6-
import org.junit.Before;
73
import org.junit.Test;
8-
import java.util.*;
94
import java.util.concurrent.CountDownLatch;
105
import java.util.concurrent.ExecutorService;
116
import java.util.concurrent.Executors;
127
import java.util.stream.IntStream;
13-
14-
import static org.hamcrest.core.Is.is;
158
import static org.junit.Assert.*;
169

1710
public class LRUCacheUnitTest {
@@ -22,9 +15,9 @@ public void addSomeDataToCache_WhenGetData_ThenIsEqualWithCacheElement() {
2215
lruCache.put("1", "test1");
2316
lruCache.put("2", "test2");
2417
lruCache.put("3", "test3");
25-
assertEquals(lruCache.get("1").get(), "test1");
26-
assertEquals(lruCache.get("2").get(), "test2");
27-
assertEquals(lruCache.get("3").get(), "test3");
18+
assertEquals("test1", lruCache.get("1").get());
19+
assertEquals("test2", lruCache.get("2").get());
20+
assertEquals("test3", lruCache.get("3").get());
2821
}
2922

3023
@Test
@@ -34,7 +27,7 @@ public void addDataToCacheToTheNumberOfSize_WhenAddOneMoreData_ThenLeastRecently
3427
lruCache.put("2", "test2");
3528
lruCache.put("3", "test3");
3629
lruCache.put("4", "test4");
37-
assertEquals(lruCache.get("1").isPresent(), false);
30+
assertFalse(lruCache.get("1").isPresent());
3831
}
3932

4033
@Test
@@ -46,14 +39,13 @@ public void runMultiThreadTask_WhenPutDataInConcurrentToCache_ThenNoDataLost() t
4639
try {
4740
IntStream.range(0, size).<Runnable>mapToObj(key -> () -> {
4841
cache.put(key, "value" + key);
49-
System.out.println(Thread.currentThread().getName() + " " + key);
5042
countDownLatch.countDown();
5143
}).forEach(executorService::submit);
5244
countDownLatch.await();
5345
} finally {
5446
executorService.shutdown();
5547
}
5648
assertEquals(cache.size(), size);
57-
IntStream.range(0, size).forEach(i -> assertEquals(cache.get(i).get(), "value" + i));
49+
IntStream.range(0, size).forEach(i -> assertEquals("value" + i, cache.get(i).get()));
5850
}
5951
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.