Search in sources :

Example 1 with StrategyService

use of com.github.robozonky.api.strategies.StrategyService in project robozonky by RoboZonky.

the class StrategyLoaderTest method standardProcessing.

@Test
void standardProcessing() {
    final StrategyService iss = mock(StrategyService.class);
    when(iss.toInvest(any())).thenReturn(Optional.of(mock(InvestmentStrategy.class)));
    assertSoftly(softly -> {
        softly.assertThat(StrategyLoader.processStrategyService(iss, "", StrategyService::toInvest)).isPresent();
        softly.assertThat(StrategyLoader.processStrategyService(iss, "", StrategyService::toSell)).isEmpty();
        softly.assertThat(StrategyLoader.processStrategyService(iss, "", StrategyService::toPurchase)).isEmpty();
    });
}
Also used : StrategyService(com.github.robozonky.api.strategies.StrategyService) Test(org.junit.jupiter.api.Test)

Example 2 with StrategyService

use of com.github.robozonky.api.strategies.StrategyService in project robozonky by RoboZonky.

the class StrategyLoaderTest method failedProcessing.

@Test
void failedProcessing() {
    final StrategyService iss = mock(StrategyService.class);
    doThrow(new IllegalStateException("Testing")).when(iss).toInvest(any());
    assertSoftly(softly -> {
        softly.assertThat(StrategyLoader.processStrategyService(iss, "", StrategyService::toInvest)).isEmpty();
        softly.assertThat(StrategyLoader.processStrategyService(iss, "", StrategyService::toSell)).isEmpty();
        softly.assertThat(StrategyLoader.processStrategyService(iss, "", StrategyService::toPurchase)).isEmpty();
    });
}
Also used : StrategyService(com.github.robozonky.api.strategies.StrategyService) Test(org.junit.jupiter.api.Test)

Example 3 with StrategyService

use of com.github.robozonky.api.strategies.StrategyService in project robozonky by RoboZonky.

the class StrategyLoaderTest method loading.

@Test
void loading() {
    final InvestmentStrategy is = (availableLoans, portfolio, restrictions) -> Stream.empty();
    final StrategyService iss = new StrategyService() {

        @Override
        public Optional<InvestmentStrategy> toInvest(final String strategy) {
            return Optional.of(is);
        }

        @Override
        public Optional<SellStrategy> toSell(final String strategy) {
            return Optional.empty();
        }

        @Override
        public Optional<PurchaseStrategy> toPurchase(final String strategy) {
            return Optional.empty();
        }
    };
    assertThat(StrategyLoader.load("", Collections.singleton(iss), StrategyService::toInvest)).contains(is);
}
Also used : Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) StrategyService(com.github.robozonky.api.strategies.StrategyService) Stream(java.util.stream.Stream) SoftAssertions(org.assertj.core.api.SoftAssertions) Optional(java.util.Optional) Assertions(org.assertj.core.api.Assertions) UUID(java.util.UUID) PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) Collections(java.util.Collections) SellStrategy(com.github.robozonky.api.strategies.SellStrategy) SellStrategy(com.github.robozonky.api.strategies.SellStrategy) PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) StrategyService(com.github.robozonky.api.strategies.StrategyService) Test(org.junit.jupiter.api.Test)

Aggregations

StrategyService (com.github.robozonky.api.strategies.StrategyService)3 Test (org.junit.jupiter.api.Test)3 InvestmentStrategy (com.github.robozonky.api.strategies.InvestmentStrategy)1 PurchaseStrategy (com.github.robozonky.api.strategies.PurchaseStrategy)1 SellStrategy (com.github.robozonky.api.strategies.SellStrategy)1 Collections (java.util.Collections)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 Stream (java.util.stream.Stream)1 Assertions (org.assertj.core.api.Assertions)1 SoftAssertions (org.assertj.core.api.SoftAssertions)1 Mockito (org.mockito.Mockito)1