@Test public void testStoreShoppingCartIsModified() throws Exception { final ShoppingCartStateService shoppingCartStateService = context.mock(ShoppingCartStateService.class, "shoppingCartStateService"); final ShopService shopService = context.mock(ShopService.class, "shopService"); final CartUpdateProcessor cartUpdateProcessor = context.mock(CartUpdateProcessor.class, "cartUpdateProcessor"); final TaskExecutor taskExecutor = context.mock(TaskExecutor.class, "taskExecutor"); final CacheManager cacheManager = context.mock(CacheManager.class, "cacheManager"); final Cache cartCache = context.mock(Cache.class, "cartCache"); final MutableShoppingCart cart = new ShoppingCartImpl(); cart.getShoppingContext().setCustomerEmail("bob@doe.com"); cart.markDirty(); final byte[] saved = serializeCart(cart); context.checking(new Expectations() {{ oneOf(cacheManager).getCache("web.shoppingCart"); will(returnValue(cartCache)); oneOf(cartCache).put(cart.getGuid(), saved); oneOf(mockCartSerDes).saveState(cart); will(returnValue(saved)); }}); final ResilientCartRepositoryImpl repo = new ResilientCartRepositoryImpl(shoppingCartStateService, shopService, cartUpdateProcessor, mockCartSerDes, 60, cacheManager, taskExecutor) { @Override void storeAsynchronously(final ShoppingCart shoppingCart) { assertSame(cart, shoppingCart); } }; assertTrue(cart.isModified()); assertEquals(cart.getGuid(), repo.storeShoppingCart(cart)); context.assertIsSatisfied(); }
@Override public String storeShoppingCart(final ShoppingCart shoppingCart) { if (shoppingCart.isModified()) { putToCache(shoppingCart.getGuid(), shoppingCart); storeAsynchronously(shoppingCart); } return shoppingCart.getGuid(); }
ResilientCartRepositoryImpl implements CartRepository { @Override public String storeShoppingCart(final ShoppingCart shoppingCart) { if (shoppingCart.isModified()) { putToCache(shoppingCart.getGuid(), shoppingCart); storeAsynchronously(shoppingCart); } return shoppingCart.getGuid(); } }
ResilientCartRepositoryImpl implements CartRepository { @Override public String storeShoppingCart(final ShoppingCart shoppingCart) { if (shoppingCart.isModified()) { putToCache(shoppingCart.getGuid(), shoppingCart); storeAsynchronously(shoppingCart); } return shoppingCart.getGuid(); } ResilientCartRepositoryImpl(final ShoppingCartStateService shoppingCartStateService,
                                       final ShopService shopService,
                                       final CartUpdateProcessor cartUpdateProcessor,
                                       final ShoppingCartStateSerDes shoppingCartStateSerDes,
                                       final int sessionExpiryInSeconds,
                                       final CacheManager cacheManager,
                                       final TaskExecutor taskExecutor);  ResilientCartRepositoryImpl(final ShoppingCartStateService shoppingCartStateService,
                                       final ShopService shopService,
                                       final CartUpdateProcessor cartUpdateProcessor,
                                       final ShoppingCartStateSerDes shoppingCartStateSerDes,
                                       final int sessionExpiryInSeconds,
                                       final CacheManager cacheManager); }
ResilientCartRepositoryImpl implements CartRepository { @Override public String storeShoppingCart(final ShoppingCart shoppingCart) { if (shoppingCart.isModified()) { putToCache(shoppingCart.getGuid(), shoppingCart); storeAsynchronously(shoppingCart); } return shoppingCart.getGuid(); } ResilientCartRepositoryImpl(final ShoppingCartStateService shoppingCartStateService,
                                       final ShopService shopService,
                                       final CartUpdateProcessor cartUpdateProcessor,
                                       final ShoppingCartStateSerDes shoppingCartStateSerDes,
                                       final int sessionExpiryInSeconds,
                                       final CacheManager cacheManager,
                                       final TaskExecutor taskExecutor);  ResilientCartRepositoryImpl(final ShoppingCartStateService shoppingCartStateService,
                                       final ShopService shopService,
                                       final CartUpdateProcessor cartUpdateProcessor,
                                       final ShoppingCartStateSerDes shoppingCartStateSerDes,
                                       final int sessionExpiryInSeconds,
                                       final CacheManager cacheManager); @Override ShoppingCart createCart(); @Override ShoppingCart getShoppingCart(final String token); @Override String storeShoppingCart(final ShoppingCart shoppingCart); @Override void evictShoppingCart(final ShoppingCart shoppingCart); }
ResilientCartRepositoryImpl implements CartRepository { @Override public String storeShoppingCart(final ShoppingCart shoppingCart) { if (shoppingCart.isModified()) { putToCache(shoppingCart.getGuid(), shoppingCart); storeAsynchronously(shoppingCart); } return shoppingCart.getGuid(); } ResilientCartRepositoryImpl(final ShoppingCartStateService shoppingCartStateService,
                                       final ShopService shopService,
                                       final CartUpdateProcessor cartUpdateProcessor,
                                       final ShoppingCartStateSerDes shoppingCartStateSerDes,
                                       final int sessionExpiryInSeconds,
                                       final CacheManager cacheManager,
                                       final TaskExecutor taskExecutor);  ResilientCartRepositoryImpl(final ShoppingCartStateService shoppingCartStateService,
                                       final ShopService shopService,
                                       final CartUpdateProcessor cartUpdateProcessor,
                                       final ShoppingCartStateSerDes shoppingCartStateSerDes,
                                       final int sessionExpiryInSeconds,
                                       final CacheManager cacheManager); @Override ShoppingCart createCart(); @Override ShoppingCart getShoppingCart(final String token); @Override String storeShoppingCart(final ShoppingCart shoppingCart); @Override void evictShoppingCart(final ShoppingCart shoppingCart);  }