@Test public void getOfferIdsFirstInvocation() throws Exception { doReturn(Arrays.asList("offer1", "offer2")).when(storageClient).getOffers("strategy1"); StrategyIdOfferIdLoader instance = new StrategyIdOfferIdLoader(storageClientFactory); List<String> strategy1_Offers = instance.getOfferIds("strategy1"); assertThat(strategy1_Offers).containsExactlyInAnyOrder("offer1", "offer2"); verify(storageClient).getOffers(anyString()); }
public List<String> getOfferIds(String strategyId) throws ProcessingException { if (offerIdsByStrategyId.containsKey(strategyId)) { return offerIdsByStrategyId.get(strategyId); } try (StorageClient storageClient = storageClientFactory.getClient()) { List<String> offers = storageClient.getOffers(strategyId); if (CollectionUtils.isEmpty(offers)) { throw new IllegalStateException("No offers found for strategy " + strategyId); } offerIdsByStrategyId.put(strategyId, offers); return offers; } catch (StorageServerClientException | StorageNotFoundClientException e) { throw new ProcessingException("Could not load offer id list for strategy " + strategyId, e); } }
StrategyIdOfferIdLoader { public List<String> getOfferIds(String strategyId) throws ProcessingException { if (offerIdsByStrategyId.containsKey(strategyId)) { return offerIdsByStrategyId.get(strategyId); } try (StorageClient storageClient = storageClientFactory.getClient()) { List<String> offers = storageClient.getOffers(strategyId); if (CollectionUtils.isEmpty(offers)) { throw new IllegalStateException("No offers found for strategy " + strategyId); } offerIdsByStrategyId.put(strategyId, offers); return offers; } catch (StorageServerClientException | StorageNotFoundClientException e) { throw new ProcessingException("Could not load offer id list for strategy " + strategyId, e); } } }
StrategyIdOfferIdLoader { public List<String> getOfferIds(String strategyId) throws ProcessingException { if (offerIdsByStrategyId.containsKey(strategyId)) { return offerIdsByStrategyId.get(strategyId); } try (StorageClient storageClient = storageClientFactory.getClient()) { List<String> offers = storageClient.getOffers(strategyId); if (CollectionUtils.isEmpty(offers)) { throw new IllegalStateException("No offers found for strategy " + strategyId); } offerIdsByStrategyId.put(strategyId, offers); return offers; } catch (StorageServerClientException | StorageNotFoundClientException e) { throw new ProcessingException("Could not load offer id list for strategy " + strategyId, e); } } StrategyIdOfferIdLoader(StorageClientFactory storageClientFactory); }
StrategyIdOfferIdLoader { public List<String> getOfferIds(String strategyId) throws ProcessingException { if (offerIdsByStrategyId.containsKey(strategyId)) { return offerIdsByStrategyId.get(strategyId); } try (StorageClient storageClient = storageClientFactory.getClient()) { List<String> offers = storageClient.getOffers(strategyId); if (CollectionUtils.isEmpty(offers)) { throw new IllegalStateException("No offers found for strategy " + strategyId); } offerIdsByStrategyId.put(strategyId, offers); return offers; } catch (StorageServerClientException | StorageNotFoundClientException e) { throw new ProcessingException("Could not load offer id list for strategy " + strategyId, e); } } StrategyIdOfferIdLoader(StorageClientFactory storageClientFactory); List<String> getOfferIds(String strategyId); }
StrategyIdOfferIdLoader { public List<String> getOfferIds(String strategyId) throws ProcessingException { if (offerIdsByStrategyId.containsKey(strategyId)) { return offerIdsByStrategyId.get(strategyId); } try (StorageClient storageClient = storageClientFactory.getClient()) { List<String> offers = storageClient.getOffers(strategyId); if (CollectionUtils.isEmpty(offers)) { throw new IllegalStateException("No offers found for strategy " + strategyId); } offerIdsByStrategyId.put(strategyId, offers); return offers; } catch (StorageServerClientException | StorageNotFoundClientException e) { throw new ProcessingException("Could not load offer id list for strategy " + strategyId, e); } } StrategyIdOfferIdLoader(StorageClientFactory storageClientFactory); List<String> getOfferIds(String strategyId);  }