Skip to content

Commit

Permalink
test: Fix Sonar test whines (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
gazbert committed Nov 14, 2024
1 parent 1e718bd commit de5a44a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.junit.jupiter.api.Assertions.assertNull;

import com.gazbert.bxbot.datastore.yaml.ConfigurationManager;
import com.gazbert.bxbot.datastore.yaml.strategy.StrategiesType;
Expand Down Expand Up @@ -91,45 +92,31 @@ void whenFindAllCalledThenExpectServiceToReturnAllStrategyConfigs() {
new StrategyConfigYamlRepository(configurationManager);
final List<StrategyConfig> strategyConfigItems = strategyConfigRepository.findAll();

assertThat(strategyConfigItems.size()).isEqualTo(2);
assertThat(strategyConfigItems).hasSize(2);

assertThat(strategyConfigItems.get(0).getId()).isEqualTo(STRAT_ID_1);
assertThat(strategyConfigItems.get(0).getName()).isEqualTo(STRAT_NAME_1);
assertThat(strategyConfigItems.get(0).getDescription()).isEqualTo(STRAT_DESCRIPTION_1);
assertThat(strategyConfigItems.get(0).getClassName()).isEqualTo(STRAT_CLASSNAME_1);
assertThat(strategyConfigItems.get(0).getConfigItems().containsKey(BUY_PRICE_CONFIG_ITEM_KEY))
.isTrue();
assertThat(
strategyConfigItems.get(0).getConfigItems().containsValue(BUY_PRICE_CONFIG_ITEM_VALUE))
.isTrue();
assertThat(
strategyConfigItems.get(0).getConfigItems().containsKey(AMOUNT_TO_BUY_CONFIG_ITEM_KEY))
.isTrue();
assertThat(
strategyConfigItems
.get(0)
.getConfigItems()
.containsValue(AMOUNT_TO_BUY_CONFIG_ITEM_VALUE))
.isTrue();
assertThat(strategyConfigItems.get(0).getConfigItems()).containsKey(BUY_PRICE_CONFIG_ITEM_KEY);
assertThat(strategyConfigItems.get(0).getConfigItems())
.containsValue(BUY_PRICE_CONFIG_ITEM_VALUE);
assertThat(strategyConfigItems.get(0).getConfigItems())
.containsKey(AMOUNT_TO_BUY_CONFIG_ITEM_KEY);
assertThat(strategyConfigItems.get(0).getConfigItems())
.containsValue(AMOUNT_TO_BUY_CONFIG_ITEM_VALUE);

assertThat(strategyConfigItems.get(1).getId()).isEqualTo(STRAT_ID_2);
assertThat(strategyConfigItems.get(1).getName()).isEqualTo(STRAT_NAME_2);
assertThat(strategyConfigItems.get(1).getDescription()).isEqualTo(STRAT_DESCRIPTION_2);
assertThat(strategyConfigItems.get(1).getClassName()).isEqualTo(STRAT_CLASSNAME_2);
assertThat(strategyConfigItems.get(1).getConfigItems().containsKey(BUY_PRICE_CONFIG_ITEM_KEY))
.isTrue();
assertThat(
strategyConfigItems.get(1).getConfigItems().containsValue(BUY_PRICE_CONFIG_ITEM_VALUE))
.isTrue();
assertThat(
strategyConfigItems.get(1).getConfigItems().containsKey(AMOUNT_TO_BUY_CONFIG_ITEM_KEY))
.isTrue();
assertThat(
strategyConfigItems
.get(1)
.getConfigItems()
.containsValue(AMOUNT_TO_BUY_CONFIG_ITEM_VALUE))
.isTrue();
assertThat(strategyConfigItems.get(1).getConfigItems()).containsKey(BUY_PRICE_CONFIG_ITEM_KEY);
assertThat(strategyConfigItems.get(1).getConfigItems())
.containsValue(BUY_PRICE_CONFIG_ITEM_VALUE);
assertThat(strategyConfigItems.get(1).getConfigItems())
.containsKey(AMOUNT_TO_BUY_CONFIG_ITEM_KEY);
assertThat(strategyConfigItems.get(1).getConfigItems())
.containsValue(AMOUNT_TO_BUY_CONFIG_ITEM_VALUE);

EasyMock.verify(configurationManager);
}
Expand All @@ -151,11 +138,10 @@ void whenFindByIdCalledWithKnownIdThenReturnMatchingStrategyConfig() {
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();
assertThat(strategyConfig.getConfigItems()).containsKey(BUY_PRICE_CONFIG_ITEM_KEY);
assertThat(strategyConfig.getConfigItems()).containsValue(BUY_PRICE_CONFIG_ITEM_VALUE);
assertThat(strategyConfig.getConfigItems()).containsKey(AMOUNT_TO_BUY_CONFIG_ITEM_KEY);
assertThat(strategyConfig.getConfigItems()).containsValue(AMOUNT_TO_BUY_CONFIG_ITEM_VALUE);

EasyMock.verify(configurationManager);
}
Expand All @@ -173,7 +159,7 @@ void whenFindByIdCalledWithUnknownIdThenReturnNullStrategyConfig() {
new StrategyConfigYamlRepository(configurationManager);
final StrategyConfig strategyConfig = strategyConfigRepository.findById(UNKNOWN_STRAT_ID);

assertThat(strategyConfig).isEqualTo(null);
assertNull(strategyConfig);
EasyMock.verify(configurationManager);
}

Expand Down Expand Up @@ -205,11 +191,10 @@ void whenSaveCalledWithKnownIdThenReturnUpdatedStrategyConfig() {
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();
assertThat(strategyConfig.getConfigItems()).containsKey(BUY_PRICE_CONFIG_ITEM_KEY);
assertThat(strategyConfig.getConfigItems()).containsValue(BUY_PRICE_CONFIG_ITEM_VALUE);
assertThat(strategyConfig.getConfigItems()).containsKey(AMOUNT_TO_BUY_CONFIG_ITEM_KEY);
assertThat(strategyConfig.getConfigItems()).containsValue(AMOUNT_TO_BUY_CONFIG_ITEM_VALUE);

EasyMock.verify(configurationManager);
}
Expand All @@ -228,7 +213,7 @@ void whenSaveCalledWithUnknownIdThenReturnEmptyStrategyConfig() {
final StrategyConfig strategyConfig =
strategyConfigRepository.save(someExternalStrategyConfigWithUnknownId());

assertThat(strategyConfig).isEqualTo(null);
assertNull(strategyConfig);
EasyMock.verify(configurationManager);
}

Expand Down Expand Up @@ -257,11 +242,10 @@ void whenSaveCalledWithEmptyIdThenExpectCreatedStrategyConfigToBeReturned() {
assertThat(strategyConfig.getName()).isEqualTo(NEW_STRAT_NAME);
assertThat(strategyConfig.getDescription()).isEqualTo(NEW_STRAT_DESCRIPTION);
assertThat(strategyConfig.getClassName()).isEqualTo(NEW_STRAT_CLASSNAME);
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();
assertThat(strategyConfig.getConfigItems()).containsKey(BUY_PRICE_CONFIG_ITEM_KEY);
assertThat(strategyConfig.getConfigItems()).containsValue(BUY_PRICE_CONFIG_ITEM_VALUE);
assertThat(strategyConfig.getConfigItems()).containsKey(AMOUNT_TO_BUY_CONFIG_ITEM_KEY);
assertThat(strategyConfig.getConfigItems()).containsValue(AMOUNT_TO_BUY_CONFIG_ITEM_VALUE);

EasyMock.verify(configurationManager);
}
Expand All @@ -288,11 +272,10 @@ void whenDeleteCalledWithKnownIdThenReturnDeletedStrategyConfig() {
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();
assertThat(strategyConfig.getConfigItems()).containsKey(BUY_PRICE_CONFIG_ITEM_KEY);
assertThat(strategyConfig.getConfigItems()).containsValue(BUY_PRICE_CONFIG_ITEM_VALUE);
assertThat(strategyConfig.getConfigItems()).containsKey(AMOUNT_TO_BUY_CONFIG_ITEM_KEY);
assertThat(strategyConfig.getConfigItems()).containsValue(AMOUNT_TO_BUY_CONFIG_ITEM_VALUE);

EasyMock.verify(configurationManager);
}
Expand All @@ -310,7 +293,7 @@ void whenDeleteCalledWithUnknownIdThenReturnEmptyStrategyConfig() {
new StrategyConfigYamlRepository(configurationManager);
final StrategyConfig strategyConfig = strategyConfigRepository.delete(UNKNOWN_STRAT_ID);

assertThat(strategyConfig).isEqualTo(null);
assertNull(strategyConfig);
EasyMock.verify(configurationManager);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,10 @@ void testSavingConfigToYamlIsSuccessful() throws Exception {
.isEqualTo(STRAT_CLASSNAME_1);
assertThat(strategiesReloaded.getStrategies().get(0).getBeanName()).isNull();

assertThat(
strategiesReloaded
.getStrategies()
.get(0)
.getConfigItems()
.get(BUY_PRICE_CONFIG_ITEM_KEY))
.isEqualTo(BUY_PRICE_CONFIG_ITEM_VALUE);
assertThat(
strategiesReloaded
.getStrategies()
.get(0)
.getConfigItems()
.get(AMOUNT_TO_BUY_CONFIG_ITEM_KEY))
.isEqualTo(AMOUNT_TO_BUY_CONFIG_ITEM_VALUE);
assertThat(strategiesReloaded.getStrategies().get(0).getConfigItems())
.containsEntry(BUY_PRICE_CONFIG_ITEM_KEY, BUY_PRICE_CONFIG_ITEM_VALUE);
assertThat(strategiesReloaded.getStrategies().get(0).getConfigItems())
.containsEntry(AMOUNT_TO_BUY_CONFIG_ITEM_KEY, AMOUNT_TO_BUY_CONFIG_ITEM_VALUE);

// Strat 2
assertThat(strategiesReloaded.getStrategies().get(1).getId()).isEqualTo(STRAT_ID_2);
Expand All @@ -219,20 +209,10 @@ void testSavingConfigToYamlIsSuccessful() throws Exception {
assertThat(strategiesReloaded.getStrategies().get(1).getBeanName())
.isEqualTo(STRAT_BEAN_NAME_2);

assertThat(
strategiesReloaded
.getStrategies()
.get(1)
.getConfigItems()
.get(BUY_PRICE_CONFIG_ITEM_KEY))
.isEqualTo(BUY_PRICE_CONFIG_ITEM_VALUE);
assertThat(
strategiesReloaded
.getStrategies()
.get(1)
.getConfigItems()
.get(AMOUNT_TO_BUY_CONFIG_ITEM_KEY))
.isEqualTo(AMOUNT_TO_BUY_CONFIG_ITEM_VALUE);
assertThat(strategiesReloaded.getStrategies().get(1).getConfigItems())
.containsEntry(BUY_PRICE_CONFIG_ITEM_KEY, BUY_PRICE_CONFIG_ITEM_VALUE);
assertThat(strategiesReloaded.getStrategies().get(1).getConfigItems())
.containsEntry(AMOUNT_TO_BUY_CONFIG_ITEM_KEY, AMOUNT_TO_BUY_CONFIG_ITEM_VALUE);

// cleanup
Files.delete(FileSystems.getDefault().getPath(YAML_CONFIG_TO_SAVE_FILENAME));
Expand Down

0 comments on commit de5a44a

Please sign in to comment.