BAEL-3459 updated cache2k example and test cases (#8732)

This commit is contained in:
Kamlesh Kumar
2020-02-21 09:16:22 +05:30
committed by GitHub
parent 409ebc1a90
commit a73581fbaf
8 changed files with 55 additions and 63 deletions
@@ -6,12 +6,13 @@ import org.junit.Test;
public class ProductHelperUnitTest {
ProductHelper productHelper = new ProductHelper();
@Test
public void whenInvokedGetDiscount_thenGetItFromCache() {
public void whenInvokedGetDiscountTwice_thenGetItFromCache() {
ProductHelper productHelper = new ProductHelper();
assertTrue(productHelper.getCacheMissCount() == 0);
assertTrue(productHelper.getDiscount("Sports") == 20);
assertTrue(productHelper.getDiscount("Electronics") == 0);
assertTrue(productHelper.getDiscount("Sports") == 20);
assertTrue(productHelper.getCacheMissCount() == 1);
}
}
@@ -6,12 +6,16 @@ import org.junit.Test;
public class ProductHelperUsingLoaderUnitTest {
ProductHelperUsingLoader productHelper = new ProductHelperUsingLoader();
@Test
public void whenInvokedGetDiscount_thenPopulateCache() {
public void whenInvokedGetDiscount_thenPopulateCacheUsingLoader() {
ProductHelperUsingLoader productHelper = new ProductHelperUsingLoader();
assertTrue(productHelper.getCacheMissCount() == 0);
assertTrue(productHelper.getDiscount("Sports") == 20);
assertTrue(productHelper.getCacheMissCount() == 1);
assertTrue(productHelper.getDiscount("Electronics") == 10);
assertTrue(productHelper.getCacheMissCount() == 2);
}
}
@@ -6,10 +6,9 @@ import org.junit.Test;
public class ProductHelperWithEventListenerUnitTest {
ProductHelperWithEventListener productHelper = new ProductHelperWithEventListener();
@Test
public void whenEntryAddedInCache_thenEventListenerCalled() {
ProductHelperWithEventListener productHelper = new ProductHelperWithEventListener();
assertTrue(productHelper.getDiscount("Sports") == 20);
}
@@ -6,13 +6,17 @@ import org.junit.Test;
public class ProductHelperWithExpiryUnitTest {
ProductHelperWithExpiry productHelper = new ProductHelperWithExpiry();
@Test
public void whenInvokedGetDiscountForExpiredProduct_thenNoDiscount() throws InterruptedException {
public void whenInvokedGetDiscountAfterExpiration_thenDiscountCalculatedAgain() throws InterruptedException {
ProductHelperWithExpiry productHelper = new ProductHelperWithExpiry();
assertTrue(productHelper.getCacheMissCount() == 0);
assertTrue(productHelper.getDiscount("Sports") == 20);
assertTrue(productHelper.getCacheMissCount() == 1);
Thread.sleep(20);
assertTrue(productHelper.getDiscount("Sports") == 0);
assertTrue(productHelper.getDiscount("Sports") == 20);
assertTrue(productHelper.getCacheMissCount() == 2);
}
}