/** * Make sure that the adjust favourite count works when wrapped store throws runtime exception. */ @Test public void testAdjustFavouriteFailWithRuntimeException() { deletegateStore.getSearchRequest(searchRequest3.getId()); mockController.setReturnValue(searchRequest3); deletegateStore.adjustFavouriteCount(searchRequest3.getId(), Integer.MAX_VALUE); mockController.setThrowable( new RuntimeException("testAdjustFavouriteFailWithRuntimeException")); deletegateStore.getSearchRequest(searchRequest3.getId()); mockController.setReturnValue(searchRequest3); mockController.replay(); // prime the cache for the test. deletegateStore.getSearchRequest(searchRequest3.getId()); // adjust should fail. try { cachingStore.adjustFavouriteCount(searchRequest3.getId(), Integer.MAX_VALUE); fail("Exception should have been thrown."); } catch (Exception expected) { } // this call should not be cached. assertEqualsNotSame(searchRequest3, cachingStore.getSearchRequest(searchRequest3.getId())); mockController.verify(); }
/** Make sure that the adjust favourite count works when entity is in the cache. */ @Test public void testAdjustFavouriteCountInCache() { deletegateStore.adjustFavouriteCount(searchRequest2.getId(), 10); mockController.setReturnValue(searchRequest2); mockController.replay(); // adjust the search request. assertEqualsNotSame( searchRequest2, cachingStore.adjustFavouriteCount(searchRequest2.getId(), 10)); // all of these calls should be cached. assertEqualsNotSame(searchRequest2, cachingStore.getSearchRequest(searchRequest2.getId())); assertEqualsNotSame(searchRequest2, cachingStore.getSearchRequest(searchRequest2.getId())); assertEqualsNotSame(searchRequest2, cachingStore.getSearchRequest(searchRequest2.getId())); mockController.verify(); }
/** Make sure that the adjust favourite count works when wrapped store returns null. */ @Test public void testAdjustFavouriteFailWithNull() { deletegateStore.getSearchRequest(searchRequest3.getId()); mockController.setReturnValue(searchRequest3); deletegateStore.adjustFavouriteCount(searchRequest3.getId(), Integer.MAX_VALUE); mockController.setReturnValue(null); deletegateStore.getSearchRequest(searchRequest3.getId()); mockController.setReturnValue(searchRequest3); mockController.replay(); // prime the cache for the test. deletegateStore.getSearchRequest(searchRequest3.getId()); // adjust should fail. assertNull(cachingStore.adjustFavouriteCount(searchRequest3.getId(), Integer.MAX_VALUE)); // this call should not be cached. assertEqualsNotSame(searchRequest3, cachingStore.getSearchRequest(searchRequest3.getId())); mockController.verify(); }