Bael 4464 (#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
This commit is contained in:
parent
b39c550ff6
commit
0ed3f46015
|
@ -1,17 +1,10 @@
|
|||
package com.baeldung.lrucache;
|
||||
|
||||
import com.baeldung.lrucache.Cache;
|
||||
import com.baeldung.lrucache.LRUCache;
|
||||
import org.hamcrest.core.AllOf;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class LRUCacheUnitTest {
|
||||
|
@ -22,9 +15,9 @@ public class LRUCacheUnitTest {
|
|||
lruCache.put("1", "test1");
|
||||
lruCache.put("2", "test2");
|
||||
lruCache.put("3", "test3");
|
||||
assertEquals(lruCache.get("1").get(), "test1");
|
||||
assertEquals(lruCache.get("2").get(), "test2");
|
||||
assertEquals(lruCache.get("3").get(), "test3");
|
||||
assertEquals("test1", lruCache.get("1").get());
|
||||
assertEquals("test2", lruCache.get("2").get());
|
||||
assertEquals("test3", lruCache.get("3").get());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -34,7 +27,7 @@ public class LRUCacheUnitTest {
|
|||
lruCache.put("2", "test2");
|
||||
lruCache.put("3", "test3");
|
||||
lruCache.put("4", "test4");
|
||||
assertEquals(lruCache.get("1").isPresent(), false);
|
||||
assertFalse(lruCache.get("1").isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -46,7 +39,6 @@ public class LRUCacheUnitTest {
|
|||
try {
|
||||
IntStream.range(0, size).<Runnable>mapToObj(key -> () -> {
|
||||
cache.put(key, "value" + key);
|
||||
System.out.println(Thread.currentThread().getName() + " " + key);
|
||||
countDownLatch.countDown();
|
||||
}).forEach(executorService::submit);
|
||||
countDownLatch.await();
|
||||
|
@ -54,6 +46,6 @@ public class LRUCacheUnitTest {
|
|||
executorService.shutdown();
|
||||
}
|
||||
assertEquals(cache.size(), size);
|
||||
IntStream.range(0, size).forEach(i -> assertEquals(cache.get(i).get(), "value" + i));
|
||||
IntStream.range(0, size).forEach(i -> assertEquals("value" + i, cache.get(i).get()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue