BAEL-3459 updated cache2k example and test cases (#8732)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-3
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user