StrategyConfigYamlRepository implements StrategyConfigRepository { @Override public StrategyConfig findById(String id) { LOG.info(() -> "Fetching config for Strategy id: " + id); final StrategiesType strategiesType = ConfigurationManager.loadConfig(StrategiesType.class, STRATEGIES_CONFIG_YAML_FILENAME); return adaptInternalToExternalConfig( strategiesType.getStrategies().stream() .filter(item -> item.getId().equals(id)) .distinct() .collect(Collectors.toList())); }  @Override List<StrategyConfig> findAll(); @Override StrategyConfig findById(String id); @Override StrategyConfig save(StrategyConfig config); @Override StrategyConfig delete(String id);  }
@Test public void whenFindByIdCalledWithKnownIdThenReturnMatchingStrategyConfig() { expect( ConfigurationManager.loadConfig( eq(StrategiesType.class), eq(STRATEGIES_CONFIG_YAML_FILENAME))) .andReturn(allTheInternalStrategiesConfig()); PowerMock.replayAll(); final StrategyConfigRepository strategyConfigRepository = new StrategyConfigYamlRepository(); final StrategyConfig strategyConfig = strategyConfigRepository.findById(STRAT_ID_1); assertThat(strategyConfig.getId()).isEqualTo(STRAT_ID_1); assertThat(strategyConfig.getName()).isEqualTo(STRAT_NAME_1); assertThat(strategyConfig.getDescription()).isEqualTo(STRAT_DESCRIPTION_1); assertThat(strategyConfig.getClassName()).isEqualTo(STRAT_CLASSNAME_1); assertThat(strategyConfig.getConfigItems().containsKey(BUY_PRICE_CONFIG_ITEM_KEY)).isTrue(); assertThat(strategyConfig.getConfigItems().containsValue(BUY_PRICE_CONFIG_ITEM_VALUE)).isTrue(); assertThat(strategyConfig.getConfigItems().containsKey(AMOUNT_TO_BUY_CONFIG_ITEM_KEY)).isTrue(); assertThat(strategyConfig.getConfigItems().containsValue(AMOUNT_TO_BUY_CONFIG_ITEM_VALUE)) .isTrue(); PowerMock.verifyAll(); }
@Test public void whenFindByIdCalledWithUnknownIdThenReturnNullStrategyConfig() { expect( ConfigurationManager.loadConfig( eq(StrategiesType.class), eq(STRATEGIES_CONFIG_YAML_FILENAME))) .andReturn(allTheInternalStrategiesConfig()); PowerMock.replayAll(); final StrategyConfigRepository strategyConfigRepository = new StrategyConfigYamlRepository(); final StrategyConfig strategyConfig = strategyConfigRepository.findById(UNKNOWN_STRAT_ID); assertThat(strategyConfig).isEqualTo(null); PowerMock.verifyAll(); }