BAEL-3459: Introduction to cache2k (#8651)

This commit is contained in:
Kamlesh Kumar
2020-02-06 08:37:19 +05:30
committed by GitHub
parent 8047fc333a
commit a51dd49517
9 changed files with 249 additions and 1 deletions
@@ -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);
}
}
@@ -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);
}
}