@Test public void whenDeleteCalledWithUnknownIdThenReturnEmptyMarket() { expect(ConfigurationManager.loadConfig(eq(MarketsType.class), eq(MARKETS_CONFIG_YAML_FILENAME))) .andReturn(allTheInternalMarketsConfig()); PowerMock.replayAll(); final MarketConfigRepository marketConfigRepository = new MarketConfigYamlRepository(); final MarketConfig marketConfig = marketConfigRepository.delete(UNKNOWN_MARKET_ID); assertThat(marketConfig).isNull(); PowerMock.verifyAll(); }
@Override public MarketConfig delete(String id) { LOG.info(() -> "Deleting Market config for id: " + id); final MarketsType marketsType = ConfigurationManager.loadConfig(MarketsType.class, MARKETS_CONFIG_YAML_FILENAME); final List<MarketConfig> marketConfigs = marketsType.getMarkets().stream() .filter(item -> item.getId().equals(id)) .distinct() .collect(Collectors.toList()); if (!marketConfigs.isEmpty()) { final MarketConfig marketToRemove = marketConfigs.get(0); marketsType.getMarkets().remove(marketToRemove); ConfigurationManager.saveConfig(MarketsType.class, marketsType, MARKETS_CONFIG_YAML_FILENAME); return adaptInternalToExternalConfig(Collections.singletonList(marketToRemove)); } else { LOG.warn( () -> "Trying to delete MarketConfig but id does not exist. MarketConfig id: " + id + EXISTING_MARKET_CONFIG + marketsType.getMarkets()); return null; } }
MarketConfigYamlRepository implements MarketConfigRepository { @Override public MarketConfig delete(String id) { LOG.info(() -> "Deleting Market config for id: " + id); final MarketsType marketsType = ConfigurationManager.loadConfig(MarketsType.class, MARKETS_CONFIG_YAML_FILENAME); final List<MarketConfig> marketConfigs = marketsType.getMarkets().stream() .filter(item -> item.getId().equals(id)) .distinct() .collect(Collectors.toList()); if (!marketConfigs.isEmpty()) { final MarketConfig marketToRemove = marketConfigs.get(0); marketsType.getMarkets().remove(marketToRemove); ConfigurationManager.saveConfig(MarketsType.class, marketsType, MARKETS_CONFIG_YAML_FILENAME); return adaptInternalToExternalConfig(Collections.singletonList(marketToRemove)); } else { LOG.warn( () -> "Trying to delete MarketConfig but id does not exist. MarketConfig id: " + id + EXISTING_MARKET_CONFIG + marketsType.getMarkets()); return null; } } }
MarketConfigYamlRepository implements MarketConfigRepository { @Override public MarketConfig delete(String id) { LOG.info(() -> "Deleting Market config for id: " + id); final MarketsType marketsType = ConfigurationManager.loadConfig(MarketsType.class, MARKETS_CONFIG_YAML_FILENAME); final List<MarketConfig> marketConfigs = marketsType.getMarkets().stream() .filter(item -> item.getId().equals(id)) .distinct() .collect(Collectors.toList()); if (!marketConfigs.isEmpty()) { final MarketConfig marketToRemove = marketConfigs.get(0); marketsType.getMarkets().remove(marketToRemove); ConfigurationManager.saveConfig(MarketsType.class, marketsType, MARKETS_CONFIG_YAML_FILENAME); return adaptInternalToExternalConfig(Collections.singletonList(marketToRemove)); } else { LOG.warn( () -> "Trying to delete MarketConfig but id does not exist. MarketConfig id: " + id + EXISTING_MARKET_CONFIG + marketsType.getMarkets()); return null; } }  }
MarketConfigYamlRepository implements MarketConfigRepository { @Override public MarketConfig delete(String id) { LOG.info(() -> "Deleting Market config for id: " + id); final MarketsType marketsType = ConfigurationManager.loadConfig(MarketsType.class, MARKETS_CONFIG_YAML_FILENAME); final List<MarketConfig> marketConfigs = marketsType.getMarkets().stream() .filter(item -> item.getId().equals(id)) .distinct() .collect(Collectors.toList()); if (!marketConfigs.isEmpty()) { final MarketConfig marketToRemove = marketConfigs.get(0); marketsType.getMarkets().remove(marketToRemove); ConfigurationManager.saveConfig(MarketsType.class, marketsType, MARKETS_CONFIG_YAML_FILENAME); return adaptInternalToExternalConfig(Collections.singletonList(marketToRemove)); } else { LOG.warn( () -> "Trying to delete MarketConfig but id does not exist. MarketConfig id: " + id + EXISTING_MARKET_CONFIG + marketsType.getMarkets()); return null; } }  @Override List<MarketConfig> findAll(); @Override MarketConfig findById(String id); @Override MarketConfig save(MarketConfig config); @Override MarketConfig delete(String id); }
MarketConfigYamlRepository implements MarketConfigRepository { @Override public MarketConfig delete(String id) { LOG.info(() -> "Deleting Market config for id: " + id); final MarketsType marketsType = ConfigurationManager.loadConfig(MarketsType.class, MARKETS_CONFIG_YAML_FILENAME); final List<MarketConfig> marketConfigs = marketsType.getMarkets().stream() .filter(item -> item.getId().equals(id)) .distinct() .collect(Collectors.toList()); if (!marketConfigs.isEmpty()) { final MarketConfig marketToRemove = marketConfigs.get(0); marketsType.getMarkets().remove(marketToRemove); ConfigurationManager.saveConfig(MarketsType.class, marketsType, MARKETS_CONFIG_YAML_FILENAME); return adaptInternalToExternalConfig(Collections.singletonList(marketToRemove)); } else { LOG.warn( () -> "Trying to delete MarketConfig but id does not exist. MarketConfig id: " + id + EXISTING_MARKET_CONFIG + marketsType.getMarkets()); return null; } }  @Override List<MarketConfig> findAll(); @Override MarketConfig findById(String id); @Override MarketConfig save(MarketConfig config); @Override MarketConfig delete(String id);  }