BAEL-3459: Introduction to cache2k (#8651)
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.cache2k;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ProductHelperUnitTest {
|
||||
|
||||
ProductHelper productHelper = new ProductHelper();
|
||||
|
||||
@Test
|
||||
public void whenInvokedGetDiscount_thenGetItFromCache() {
|
||||
assertTrue(productHelper.getDiscount("Sports") == 20);
|
||||
assertTrue(productHelper.getDiscount("Electronics") == 0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.cache2k;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ProductHelperUsingLoaderUnitTest {
|
||||
|
||||
ProductHelperUsingLoader productHelper = new ProductHelperUsingLoader();
|
||||
|
||||
@Test
|
||||
public void whenInvokedGetDiscount_thenPopulateCache() {
|
||||
assertTrue(productHelper.getDiscount("Sports") == 20);
|
||||
assertTrue(productHelper.getDiscount("Electronics") == 10);
|
||||
}
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.cache2k;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ProductHelperWithEventListenerUnitTest {
|
||||
|
||||
ProductHelperWithEventListener productHelper = new ProductHelperWithEventListener();
|
||||
|
||||
@Test
|
||||
public void whenEntryAddedInCache_thenEventListenerCalled() {
|
||||
assertTrue(productHelper.getDiscount("Sports") == 20);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.cache2k;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ProductHelperWithExpiryUnitTest {
|
||||
|
||||
ProductHelperWithExpiry productHelper = new ProductHelperWithExpiry();
|
||||
|
||||
@Test
|
||||
public void whenInvokedGetDiscountForExpiredProduct_thenNoDiscount() throws InterruptedException {
|
||||
assertTrue(productHelper.getDiscount("Sports") == 20);
|
||||
Thread.sleep(20);
|
||||
assertTrue(productHelper.getDiscount("Sports") == 0);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user