Java 类org.assertj.core.api.SoftAssertions 实例源码

项目:allure-java    文件:AllureJunit5Test.java   
@Test
void shouldAddTags() {
    runClasses(TaggedTests.class);

    final List<TestResult> testResults = results.getTestResults();

    SoftAssertions softly = new SoftAssertions();

    softly.assertThat(testResults)
            .hasSize(1);

    softly.assertThat(testResults)
            .flatExtracting(TestResult::getLabels)
            .filteredOn(label -> "tag".equals(label.getName()))
            .flatExtracting(Label::getValue)
            .containsExactlyInAnyOrder(CLASS_TAG, METHOD_TAG);

    softly.assertAll();
}
项目:spring-boot-gae    文件:IndexTypeRegistryTest.java   
@Test
public void applyCollectionTypes() throws Exception {
    SoftAssertions softly = new SoftAssertions();

    softly.assertThat(lookup.apply(
            CollectionFields.class.getDeclaredField("stringList").getGenericType())
    ).isEqualTo(IndexType.TEXT);

    softly.assertThat(lookup.apply(
            CollectionFields.class.getDeclaredField("integerSet").getGenericType())
    ).isEqualTo(IndexType.NUMBER);

    softly.assertThat(lookup.apply(
            CollectionFields.class.getDeclaredField("stringArray").getGenericType())
    ).isEqualTo(IndexType.TEXT);

    softly.assertThat(lookup.apply(
            CollectionFields.class.getDeclaredField("intArray").getGenericType())
    ).isEqualTo(IndexType.NUMBER);

    softly.assertAll();
}
项目:spring-boot-gae    文件:LongAsyncSaveRepositoryTest.java   
@SuppressWarnings("Duplicates")
protected void verifyTestEntityCollectionSaved() {
    SoftAssertions softly = new SoftAssertions();

    TestLongEntity loaded1 = load(1L);
    softly.assertThat(loaded1.getId()).isEqualTo(1L);
    softly.assertThat(loaded1.getName()).isEqualTo("entity1");

    TestLongEntity loaded2 = load(2L);
    softly.assertThat(loaded2.getId()).isEqualTo(2L);
    softly.assertThat(loaded2.getName()).isEqualTo("entity2");

    TestLongEntity loaded3 = load(3L);
    softly.assertThat(loaded3.getId()).isEqualTo(3L);
    softly.assertThat(loaded3.getName()).isEqualTo("entity3");

    softly.assertAll();
}
项目:spring-boot-gae    文件:StringAsyncSaveRepositoryTest.java   
@SuppressWarnings("Duplicates")
protected void verifyTestEntityCollectionSaved() {
    SoftAssertions softly = new SoftAssertions();

    TestStringEntity loaded1 = load("id1");
    softly.assertThat(loaded1.getId()).isEqualTo("id1");
    softly.assertThat(loaded1.getName()).isEqualTo("entity1");

    TestStringEntity loaded2 = load("id2");
    softly.assertThat(loaded2.getId()).isEqualTo("id2");
    softly.assertThat(loaded2.getName()).isEqualTo("entity2");

    TestStringEntity loaded3 = load("id3");
    softly.assertThat(loaded3.getId()).isEqualTo("id3");
    softly.assertThat(loaded3.getName()).isEqualTo("entity3");

    softly.assertAll();
}
项目:spring-boot-gae    文件:LongAsyncDeleteRepositoryTest.java   
protected void verifyTestEntityCollectionSaved() {
    SoftAssertions softly = new SoftAssertions();

    TestLongEntity loaded1 = load(1L);
    softly.assertThat(loaded1.getId()).isEqualTo(1L);
    softly.assertThat(loaded1.getName()).isEqualTo("entity1");

    TestLongEntity loaded2 = load(2L);
    softly.assertThat(loaded2.getId()).isEqualTo(2L);
    softly.assertThat(loaded2.getName()).isEqualTo("entity2");

    TestLongEntity loaded3 = load(3L);
    softly.assertThat(loaded3.getId()).isEqualTo(3L);
    softly.assertThat(loaded3.getName()).isEqualTo("entity3");

    softly.assertAll();
}
项目:spring-boot-gae    文件:LongSaveRepositoryTest.java   
@SuppressWarnings("Duplicates")
protected void verifyTestEntityCollectionSaved() {
    SoftAssertions softly = new SoftAssertions();

    TestLongEntity loaded1 = load(1L);
    softly.assertThat(loaded1.getId()).isEqualTo(1L);
    softly.assertThat(loaded1.getName()).isEqualTo("entity1");

    TestLongEntity loaded2 = load(2L);
    softly.assertThat(loaded2.getId()).isEqualTo(2L);
    softly.assertThat(loaded2.getName()).isEqualTo("entity2");

    TestLongEntity loaded3 = load(3L);
    softly.assertThat(loaded3.getId()).isEqualTo(3L);
    softly.assertThat(loaded3.getName()).isEqualTo("entity3");

    softly.assertAll();
}
项目:spring-boot-gae    文件:StringSaveRepositoryTest.java   
@SuppressWarnings("Duplicates")
protected void verifyTestEntityCollectionSaved() {
    SoftAssertions softly = new SoftAssertions();

    TestStringEntity loaded1 = load("id1");
    softly.assertThat(loaded1.getId()).isEqualTo("id1");
    softly.assertThat(loaded1.getName()).isEqualTo("entity1");

    TestStringEntity loaded2 = load("id2");
    softly.assertThat(loaded2.getId()).isEqualTo("id2");
    softly.assertThat(loaded2.getName()).isEqualTo("entity2");

    TestStringEntity loaded3 = load("id3");
    softly.assertThat(loaded3.getId()).isEqualTo("id3");
    softly.assertThat(loaded3.getName()).isEqualTo("entity3");

    softly.assertAll();
}
项目:log4j2-logstash-layout    文件:LogstashLayoutTest.java   
@Test
public void test_lineSeparator_suffix() {

    // Create the log event.
    SimpleMessage message = new SimpleMessage("Hello, World!");
    LogEvent logEvent = Log4jLogEvent
            .newBuilder()
            .setLoggerName(LogstashLayoutTest.class.getSimpleName())
            .setLevel(Level.INFO)
            .setMessage(message)
            .build();

    // Check line separators.
    SoftAssertions assertions = new SoftAssertions();
    test_lineSeparator_suffix(logEvent, true, assertions);
    test_lineSeparator_suffix(logEvent, false, assertions);
    assertions.assertAll();

}
项目:log4j2-logstash-layout    文件:LogstashLayoutTest.java   
private void test_lineSeparator_suffix(LogEvent logEvent, boolean prettyPrintEnabled, SoftAssertions assertions) {

        // Create the layout.
        BuiltConfiguration config = ConfigurationBuilderFactory.newConfigurationBuilder().build();
        LogstashLayout layout = LogstashLayout
                .newBuilder()
                .setConfiguration(config)
                .setTemplateUri("classpath:LogstashJsonEventLayoutV1.json")
                .setPrettyPrintEnabled(prettyPrintEnabled)
                .build();

        // Check the serialized event.
        String serializedLogEvent = layout.toSerializable(logEvent);
        String assertionCaption = String.format("testing lineSeperator (prettyPrintEnabled=%s)", prettyPrintEnabled);
        assertions.assertThat(serializedLogEvent).as(assertionCaption).endsWith("}" + System.lineSeparator());

    }
项目:robozonky    文件:RecommendedParticipationTest.java   
@Test
public void equals() {
    final Participation p = mock();
    final ParticipationDescriptor d = new ParticipationDescriptor(p);
    final RecommendedParticipation r = new RecommendedParticipation(d);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(r).isNotEqualTo(null);
        softly.assertThat(r).isNotEqualTo(UUID.randomUUID().toString());
        softly.assertThat(r).isEqualTo(r);
    });
    final RecommendedParticipation r2 = new RecommendedParticipation(d);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(r).isEqualTo(r2);
        softly.assertThat(r2).isEqualTo(r);
    });
    final RecommendedParticipation r3 = new RecommendedParticipation(new ParticipationDescriptor(mock()));
    Assertions.assertThat(r).isNotEqualTo(r3);
}
项目:robozonky    文件:RoboZonkyInstallerListenerTest.java   
@Test
public void coreWithTweaks() {
    // prepare
    final InstallData localData = RoboZonkyInstallerListenerTest.mockData();
    Mockito.when(localData.getVariable(Variables.IS_DRY_RUN.getKey())).thenReturn("true");
    Mockito.when(localData.getVariable(Variables.IS_ZONKOID_ENABLED.getKey())).thenReturn("true");
    Mockito.when(localData.getVariable(Variables.ZONKOID_TOKEN.getKey())).thenReturn("123456");
    RoboZonkyInstallerListener.setInstallData(localData);
    // execute SUT
    final CommandLinePart clp = new RoboZonkyInstallerListener().prepareCore();
    // test
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(clp.getOptions())
                .containsKey("-d")
                .containsKey("-x");
        softly.assertThat(clp.getOptions().get("-p"))
                .containsOnly(String.valueOf(RoboZonkyInstallerListener.KEYSTORE_PASSWORD));
    });
}
项目:robozonky    文件:RecommendedInvestmentTest.java   
@Test
public void equals() {
    final Investment i = mock();
    final InvestmentDescriptor d = new InvestmentDescriptor(i);
    final RecommendedInvestment r = new RecommendedInvestment(d);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(r).isNotEqualTo(null);
        softly.assertThat(r).isNotEqualTo(UUID.randomUUID().toString());
        softly.assertThat(r).isEqualTo(r);
    });
    final RecommendedInvestment r2 = new RecommendedInvestment(d);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(r).isEqualTo(r2);
        softly.assertThat(r2).isEqualTo(r);
    });
    final RecommendedInvestment r3 = new RecommendedInvestment(new InvestmentDescriptor(mock()));
    Assertions.assertThat(r).isNotEqualTo(r3);
}
项目:mybatis-dynamic-sql    文件:CriterionRendererTest.java   
@Test
public void testAliasWithIgnore() {
    SqlTable table = SqlTable.of("foo");
    SqlColumn<Integer> column = table.column("id", JDBCType.INTEGER);

    IsEqualTo<Integer> condition = IsEqualTo.of(() -> 3);
    SqlCriterion<Integer> criterion = SqlCriterion.withColumn(column)
            .withCondition(condition)
            .build();
    AtomicInteger sequence = new AtomicInteger(1);
    FragmentAndParameters fp = CriterionRenderer.withCriterion(criterion)
            .withSequence(sequence)
            .withRenderingStrategy(RenderingStrategy.MYBATIS3)
            .withTableAliasCalculator(TableAliasCalculator.empty())
            .build()
            .render();

    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(fp.fragment()).isEqualTo("id = #{parameters.p1,jdbcType=INTEGER}");
        softly.assertThat(fp.parameters().size()).isEqualTo(1);
    });
}
项目:robozonky    文件:InvestmentDescriptorTest.java   
@Test
public void equals() {
    final Investment i = mock(BigDecimal.TEN);
    final InvestmentDescriptor id = new InvestmentDescriptor(i);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(id).isNotEqualTo(null);
        softly.assertThat(id).isNotEqualTo(UUID.randomUUID().toString());
        softly.assertThat(id).isEqualTo(id);
    });
    final InvestmentDescriptor id2 = new InvestmentDescriptor(i);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(id).isEqualTo(id2);
        softly.assertThat(id2).isEqualTo(id);
    });
    final InvestmentDescriptor id3 = new InvestmentDescriptor(mock(BigDecimal.ONE));
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(id).isNotEqualTo(id3);
    });
}
项目:behaim    文件:BehaimTest.java   
private void assertFullyPopulated(SoftAssertions assertions, Person person, String breadcrumb, int level) {
    logger.trace("[{}] Checking {}", level, breadcrumb);
    assertions.assertThat(person).as(breadcrumb + " at level " + level).isNotNull();
    if (person == null) {
        return;
    }
    assertions.assertThat(person.getAnnualSalary()).as(breadcrumb + ".annualSalary at level " + level).isNotNull();
    assertions.assertThat(person.getBirthday()).as(breadcrumb + ".birthday at level " + level).isNotNull();
    assertions.assertThat(person.getName()).as(breadcrumb + ".name at level " + level).isNotNull();
    assertions.assertThat(person.getPreferredColor()).as(breadcrumb + ".preferredColor at level " + level).isNotNull();
    assertions.assertThat(person.getAlwaysNullValue()).as(breadcrumb + ".awaysNullValue at level " + level).isNull();
    assertions.assertThat(person.getSingleValue()).as(breadcrumb + ".singleValue at level " + level).isSameAs(SingleValueEnum.SINGLE_VALUE);
    if (level > 0) {
        assertFullyPopulated(assertions, person.getManager(), breadcrumb + ".manager", level - 1);

        String teamProperty = breadcrumb + ".team at level " + level;
        assertions.assertThat(person.getTeam()).as(teamProperty).isNotNull();
        if (person.getTeam() != null) {
            for (Person teamMember : person.getTeam()) {
                assertFullyPopulated(assertions, teamMember, teamProperty, level - 1);
            }
        }
    }
}
项目:robozonky    文件:SettingsTest.java   
@Test
public void defaultProperties() {
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(Settings.INSTANCE.get("user.dir", "")).isNotEqualTo("");
        softly.assertThat(Settings.INSTANCE.get(UUID.randomUUID().toString(), ""))
                .isEqualTo("");
        softly.assertThat(Settings.INSTANCE.isDebugEventStorageEnabled()).isFalse();
        softly.assertThat(Settings.INSTANCE.getTokenRefreshPeriod())
                .matches(new SettingsTest.TemporalPredicate(60));
        softly.assertThat(Settings.INSTANCE.getRemoteResourceRefreshInterval())
                .matches(new SettingsTest.TemporalPredicate(5 * 60));
        softly.assertThat(Settings.INSTANCE.getCaptchaDelay())
                .matches(new SettingsTest.TemporalPredicate(0));
        Stream.of(Rating.values()).forEach(r -> {
            softly.assertThat(Settings.INSTANCE.getCaptchaDelay(r))
                    .as(r.toString())
                    .matches(new SettingsTest.TemporalPredicate(0));
        });
        softly.assertThat(Settings.INSTANCE.getDefaultDryRunBalance()).isEqualTo(-1);
        softly.assertThat(Settings.INSTANCE.getSocketTimeout())
                .matches(new SettingsTest.TemporalPredicate(60));
        softly.assertThat(Settings.INSTANCE.getConnectionTimeout())
                .matches(new SettingsTest.TemporalPredicate(60));
        softly.assertThat(Settings.INSTANCE.getDefaultApiPageSize()).isEqualTo(100);
    });
}
项目:robozonky    文件:RunScriptGeneratorTest.java   
@Test
public void windows() throws IOException {
    final File optionsFile = getTempFile().getAbsoluteFile();
    final File root = optionsFile.getParentFile();
    final CommandLinePart cli = getCommandLine();
    final Function<CommandLinePart, File> generator =
            RunScriptGenerator.forWindows(root, optionsFile);
    final String result = new String(Files.readAllBytes(generator.apply(cli).toPath()));
    common(cli, result);
    Assertions.assertThat(result)
            .as("Missing executable file call.")
            .contains(root + "\\robozonky.bat @" + optionsFile.getAbsolutePath());
    // assert all environment variables present
    SoftAssertions.assertSoftly(softly -> cli.getEnvironmentVariables().forEach((var, value) -> {
        final String arg = var + "=" + value;
        softly.assertThat(result).as("Missing env var.").contains(arg);
    }));
    Assertions.assertThat(result).contains("\r\n");
}
项目:mybatis-dynamic-sql    文件:CriterionRendererTest.java   
@Test
public void testTypeHandlerAndAlias() {
    SqlTable table = SqlTable.of("foo");
    SqlColumn<Integer> column = table.column("id", JDBCType.INTEGER, "foo.Bar");
    IsEqualTo<Integer> condition = IsEqualTo.of(() -> 3);
    SqlCriterion<Integer> criterion = SqlCriterion.withColumn(column)
            .withCondition(condition)
            .build();
    AtomicInteger sequence = new AtomicInteger(1);
    Map<SqlTable, String> tableAliases = new HashMap<>();
    tableAliases.put(table, "a");

    FragmentAndParameters fp = CriterionRenderer.withCriterion(criterion)
            .withSequence(sequence)
            .withRenderingStrategy(RenderingStrategy.MYBATIS3)
            .withTableAliasCalculator(TableAliasCalculator.of(tableAliases))
            .build()
            .render();

    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(fp.fragment()).isEqualTo("a.id = #{parameters.p1,jdbcType=INTEGER,typeHandler=foo.Bar}");
        softly.assertThat(fp.parameters().size()).isEqualTo(1);
    });
}
项目:mybatis-dynamic-sql    文件:SimpleTableAnnotatedMapperTest.java   
@Test
public void testSelectByExampleWithTypeHandler() {
    SqlSession session = sqlSessionFactory.openSession();
    try {
        SimpleTableAnnotatedMapper mapper = session.getMapper(SimpleTableAnnotatedMapper.class);

        List<SimpleTableRecord> rows = mapper.selectByExample()
                .where(employed, isEqualTo(false))
                .orderBy(id)
                .build()
                .execute();

        SoftAssertions.assertSoftly(softly -> {
            softly.assertThat(rows.size()).isEqualTo(2);
            softly.assertThat(rows.get(0).getId()).isEqualTo(3);
            softly.assertThat(rows.get(1).getId()).isEqualTo(6);
        });
    } finally {
        session.close();
    }
}
项目:robozonky    文件:ZonkyTest.java   
@Test
public void constructor() {
    final Api<ControlApi> ca = mockApi(Mockito.mock(ControlApi.class));
    final PaginatedApi<Loan, LoanApi> la = mockApi();
    final PaginatedApi<BlockedAmount, WalletApi> wa = mockApi();
    final PaginatedApi<Investment, PortfolioApi> pa = mockApi();
    final PaginatedApi<Participation, ParticipationApi> sa = mockApi();
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThatThrownBy(() -> new Zonky(null, la, sa, pa, wa))
                .isInstanceOf(IllegalArgumentException.class);
        softly.assertThatThrownBy(() -> new Zonky(ca, null, sa, pa, wa))
                .isInstanceOf(IllegalArgumentException.class);
        softly.assertThatThrownBy(() -> new Zonky(ca, la, null, pa, wa))
                .isInstanceOf(IllegalArgumentException.class);
        softly.assertThatThrownBy(() -> new Zonky(ca, la, sa, null, wa))
                .isInstanceOf(IllegalArgumentException.class);
        softly.assertThatThrownBy(() -> new Zonky(ca, la, sa, pa, null))
                .isInstanceOf(IllegalArgumentException.class);
    });
}
项目:robozonky    文件:ZonkyTest.java   
@Test
public void streams() {
    final Api<ControlApi> ca = mockApi(Mockito.mock(ControlApi.class));
    final PaginatedApi<Loan, LoanApi> la = mockApi();
    final PaginatedApi<BlockedAmount, WalletApi> wa = mockApi();
    final PaginatedApi<Investment, PortfolioApi> pa = mockApi();
    final PaginatedApi<Participation, ParticipationApi> sa = mockApi();
    final Zonky z = new Zonky(ca, la, sa, pa, wa);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(z.getAvailableLoans()).isEmpty();
        softly.assertThat(z.getAvailableLoans(Sort.unspecified())).isEmpty();
        softly.assertThat(z.getBlockedAmounts()).isEmpty();
        softly.assertThat(z.getInvestments()).isEmpty();
        softly.assertThat(z.getInvestments(Sort.unspecified())).isEmpty();
        softly.assertThat(z.getAvailableParticipations()).isEmpty();
    });
}
项目:behaim    文件:StatisticsVisitorTest.java   
private static void assertResultIsValid(VisitationResult result, PersonFields field, Person person) {
    SoftAssertions soft = new SoftAssertions();
    soft.assertThat(result).as("result").isNotNull();
    if (result != null) {
        soft.assertThat(result.getValue()).as("result.value").isSameAs(field.getValue(person));
        soft.assertThat(result.getFieldContext()).as("result.fieldContext").isNotNull();
        if (result.getFieldContext() != null) {
            soft.assertThat(result.getFieldContext().getField()).as("result.fieldContext.field")
                    .isSameAs(field.getField());
        }
        List<PersonFields> notVisitables = Arrays.asList(PersonFields.NAME, PersonFields.ANNUALSALARY, PersonFields.BIRTHDAY, PersonFields.EMPTY_ENUM);
        soft.assertThat(result.isVisitOfValueRequired()).as("result.visitOfValueRequired")
                .isEqualTo(!notVisitables.contains(field));
    }
    soft.assertAll();
}
项目:robozonky    文件:SellingTest.java   
private void saleMade(final boolean isDryRun) {
    final Investment i = mock();
    final Zonky zonky = mockApi(i);
    final Portfolio portfolio = Portfolio.create(zonky);
    new Selling(ALL_ACCEPTING, isDryRun).accept(portfolio, mockAuthentication(zonky));
    final List<Event> e = getNewEvents();
    Assertions.assertThat(e).hasSize(5);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(e.get(0)).isInstanceOf(SellingStartedEvent.class);
        softly.assertThat(e.get(1)).isInstanceOf(SaleRecommendedEvent.class);
        softly.assertThat(e.get(2)).isInstanceOf(SaleRequestedEvent.class);
        softly.assertThat(e.get(3)).isInstanceOf(SaleOfferedEvent.class);
        softly.assertThat(e.get(4)).isInstanceOf(SellingCompletedEvent.class);
    });
    final VerificationMode m = isDryRun ? Mockito.never() : Mockito.times(1);
    Mockito.verify(i, m).setIsOnSmp(ArgumentMatchers.eq(true));
    Mockito.verify(zonky, m).sell(ArgumentMatchers.eq(i));
}
项目:robozonky    文件:DelinquentTest.java   
@Test
public void withActiveDelinquency() {
    final LocalDate since = LocalDate.now();
    final int loanId = 1;
    final Delinquent d = new Delinquent(loanId, since);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(d.getLoanId()).isEqualTo(loanId);
        softly.assertThat(d.getActiveDelinquency()).isPresent();
        softly.assertThat(d.hasActiveDelinquency()).isTrue();
        softly.assertThat(d.getDelinquencies()).hasSize(1);
    });
    final Delinquency active = d.getDelinquencies().findFirst().get();
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(active.getParent()).isEqualTo(d);
        softly.assertThat(active.getPaymentMissedDate()).isEqualTo(since);
        softly.assertThat(active.getFixedOn()).isEmpty();
    });
}
项目:robozonky    文件:CommandLinePartTest.java   
@Test
public void jvmArguments() {
    final String firstVariable = UUID.randomUUID().toString();
    final String secondVariable = UUID.randomUUID().toString();
    final String firstValue = UUID.randomUUID().toString();
    final CommandLinePart clp = new CommandLinePart()
            .setJvmArgument(firstVariable, firstValue)
            .setJvmArgument(secondVariable);
    SoftAssertions.assertSoftly(softly -> {
        final Map<String, Optional<String>> variables = clp.getJvmArguments();
        softly.assertThat(variables.get(UUID.randomUUID().toString())).isNull();
        softly.assertThat(variables.get(firstVariable)).isPresent().contains(firstValue);
        softly.assertThat(variables.get(secondVariable)).isEmpty();
        softly.assertThat(clp.getEnvironmentVariables()).isEmpty();
        softly.assertThat(clp.getOptions()).isEmpty();
        softly.assertThat(clp.getProperties()).isEmpty();
    });
}
项目:robozonky    文件:DelinquentTest.java   
@Test
public void equality() {
    final Delinquent d = new Delinquent(1);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(d).isEqualTo(d);
        softly.assertThat(d).isNotEqualTo(null);
    });
    final Delinquent d2 = new Delinquent(d.getLoanId());
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(d).isEqualTo(d2);
        softly.assertThat(d2).isEqualTo(d);
    });
    final Delinquent d3 = new Delinquent(d.getLoanId() + 1);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(d).isNotEqualTo(d3);
        softly.assertThat(d3).isNotEqualTo(d);
    });
}
项目:robozonky    文件:ParsedStrategyTest.java   
@Test
public void construct() {
    final DefaultPortfolio portfolio = DefaultPortfolio.PROGRESSIVE;
    final ParsedStrategy strategy = new ParsedStrategy(portfolio); // test for default values
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(strategy.getMinimumBalance()).isEqualTo(Defaults.MINIMUM_INVESTMENT_IN_CZK);
        softly.assertThat(strategy.getMaximumInvestmentSizeInCzk()).isEqualTo(Integer.MAX_VALUE);
        softly.assertThat(strategy.getMinimumShare(Rating.A))
                .isEqualTo(portfolio.getDefaultShare(Rating.A));
        softly.assertThat(strategy.getMaximumShare(Rating.B))
                .isEqualTo(portfolio.getDefaultShare(Rating.B));
        softly.assertThat(strategy.getMinimumInvestmentSizeInCzk(Rating.C)).isEqualTo(0);
        softly.assertThat(strategy.getMaximumInvestmentSizeInCzk(Rating.D)).isEqualTo(
                Defaults.MAXIMUM_INVESTMENT_IN_CZK);
        softly.assertThat(strategy.needsConfirmation(new LoanDescriptor(new Loan(1, 2)))).isFalse();
    });
}
项目:robozonky    文件:ParsedStrategyTest.java   
@Test
public void sellOffStarted() {
    final DefaultPortfolio portfolio = DefaultPortfolio.EMPTY;
    final DefaultValues values = new DefaultValues(portfolio);
    // activate default sell-off 3 months before the given date, which is already in the past
    values.setExitProperties(new ExitProperties(LocalDate.now().plusMonths(2)));
    final ParsedStrategy strategy = new ParsedStrategy(values, Collections.emptyList());
    // no loan or participation should be bought; every investment should be sold
    final Loan l = new Loan(1, 1000);
    final LoanDescriptor ld = new LoanDescriptor(l);
    final ParticipationDescriptor pd = mock(l);
    final Investment i = new Investment(l, 200);
    final InvestmentDescriptor id = new InvestmentDescriptor(i, l);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(strategy.getApplicableLoans(Collections.singleton(ld))).isEmpty();
        softly.assertThat(strategy.getApplicableParticipations(Collections.singleton(pd))).isEmpty();
        softly.assertThat(strategy.getApplicableInvestments(Collections.singleton(id))).containsOnly(id);
    });
}
项目:robozonky    文件:CommandLinePartTest.java   
@Test
public void environmentVariables() {
    final String firstVariable = UUID.randomUUID().toString();
    final String secondVariable = UUID.randomUUID().toString();
    final String firstValue = UUID.randomUUID().toString();
    final String secondValue = UUID.randomUUID().toString();
    final CommandLinePart clp = new CommandLinePart()
            .setEnvironmentVariable(firstVariable, firstValue)
            .setEnvironmentVariable(secondVariable, secondValue);
    SoftAssertions.assertSoftly(softly -> {
        final Map<String, String> variables = clp.getEnvironmentVariables();
        softly.assertThat(variables.get(UUID.randomUUID().toString())).isNull();
        softly.assertThat(variables.get(firstVariable)).isSameAs(firstValue);
        softly.assertThat(variables.get(secondVariable)).isSameAs(secondValue);
        softly.assertThat(clp.getJvmArguments()).isEmpty();
        softly.assertThat(clp.getOptions()).isEmpty();
        softly.assertThat(clp.getProperties()).isEmpty();
    });
}
项目:mybatis-dynamic-sql    文件:AnimalDataTest.java   
@Test
public void testGreaterThanSubselect() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);

        SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
                .from(animalData, "a")
                .where(brainWeight, isGreaterThan(select(min(brainWeight)).from(animalData, "b")))
                .build()
                .render(RenderingStrategy.MYBATIS3);

        SoftAssertions.assertSoftly(softly -> {
            softly.assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight > (select min(b.brain_weight) from AnimalData b)");

            List<AnimalData> records = mapper.selectMany(selectStatement);
            softly.assertThat(records.size()).isEqualTo(64);
        });
    } finally {
        sqlSession.close();
    }
}
项目:robozonky    文件:DelinquentsTest.java   
@Test
public void newDelinquence() {
    final Loan l = new Loan(RANDOM.nextInt(10000), 200);
    final Investment i = Mockito.spy(new Investment(l, 200));
    Mockito.doReturn(OffsetDateTime.now().minusDays(1)).when(i).getNextPaymentDate();
    final Function<Integer, Loan> f = (id) -> l;
    // make sure new delinquences are reported and stored
    Delinquents.update(Collections.singleton(i), Collections.emptyList(), INVESTMENT_SUPPLIER, f);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(Delinquents.getDelinquents()).hasSize(1);
        softly.assertThat(this.getNewEvents()).hasSize(1);
    });
    Assertions.assertThat(this.getNewEvents().get(0)).isInstanceOf(LoanNowDelinquentEvent.class);
    // make sure delinquences are persisted even when there are none present
    Delinquents.update(Collections.emptyList(), Collections.emptyList(), INVESTMENT_SUPPLIER, f);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(Delinquents.getDelinquents()).hasSize(1);
        softly.assertThat(this.getNewEvents()).hasSize(2);
    });
    Assertions.assertThat(this.getNewEvents().get(1)).isInstanceOf(LoanNoLongerDelinquentEvent.class);
    // and when they are no longer active, they're gone for good
    Delinquents.update(Collections.emptyList(), Collections.singleton(i), INVESTMENT_SUPPLIER, f);
    Assertions.assertThat(Delinquents.getDelinquents()).hasSize(0);
}
项目:mybatis-dynamic-sql    文件:AnimalDataTest.java   
@Test
public void testAvg() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);

        SelectStatementProvider selectStatement = select(avg(brainWeight).as("average"))
                .from(animalData, "a")
                .build()
                .render(RenderingStrategy.MYBATIS3);

        SoftAssertions.assertSoftly(softly -> {
            softly.assertThat(selectStatement.getSelectStatement()).isEqualTo("select avg(a.brain_weight) as average from AnimalData a");

            Double average = mapper.selectADouble(selectStatement);
            softly.assertThat(average).isEqualTo(1852.69, within(.01));
        });
    } finally {
        sqlSession.close();
    }
}
项目:robozonky    文件:DelinquencyCategoryTest.java   
@Test
public void addAndRead() {
    final int loanId = 1;
    final Function<Integer, Loan> f = (id) -> new Loan(loanId, 200);
    // store a delinquent loan
    final Delinquent d = new Delinquent(loanId);
    final Delinquency dy = d.addDelinquency(LocalDate.now().minus(minimumMatchingDuration));
    Assertions.assertThat(category.update(Collections.singleton(dy), INVESTMENT_SUPPLIER, f))
            .containsExactly(loanId);
    final List<Event> events = this.getNewEvents();
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(events).hasSize(1);
        softly.assertThat(events).first().isInstanceOf(LoanDelinquentEvent.class);
    });
    // attempt to store it again, making sure no event is fired
    Assertions.assertThat(category.update(Collections.singleton(dy), INVESTMENT_SUPPLIER, f))
            .containsExactly(loanId);
    Assertions.assertThat(this.getNewEvents()).isEqualTo(events);
    // now update with no delinquents, making sure nothing is returned
    Assertions.assertThat(category.update(Collections.emptyList(), INVESTMENT_SUPPLIER, f)).isEmpty();
    Assertions.assertThat(this.getNewEvents()).isEqualTo(events);
}
项目:JUnit-5-Quick-Start-Guide-with-AssertJ-Spring-TestFX-Mockito    文件:AssertJ_02_FluentAssertionsAndMoreFeatures.java   
/**
 * SoftAssertions are used to group assertions with different assertion bases and force all of them to run even if a previous assertion failed.
 */
@Test
void softAssertion() {
    SoftAssertions.assertSoftly(soft -> {
        // Base dummyFruits
        soft.assertThat(dummyFruits)
                .hasSize(3)
                .containsExactly(babyBanana, grannySmithApple, grapefruit);
        // Base otherDummyFruitList
        soft.assertThat(otherDummyFruitList)
                .hasSize(4)
                .containsAll(dummyFruits)
                .containsExactly(babyBanana, grannySmithApple, grapefruit, redBanana);
        // Base
        soft.assertThat(grapefruit).extracting(DummyFruit::getType).allMatch(DummyFruit.TYPE.ORANGE::equals);
    });
}
项目:robozonky    文件:PortfolioTest.java   
@Test
public void run() {
    final PortfolioOverview portfolio = Mockito.mock(PortfolioOverview.class);
    Mockito.when(portfolio.getCzkAvailable()).thenReturn(1000);
    Mockito.when(portfolio.getCzkInvested()).thenReturn(10000);
    Mockito.when(portfolio.getShareOnInvestment(ArgumentMatchers.any())).thenReturn(BigDecimal.ONE);
    Mockito.when(portfolio.getCzkInvested(ArgumentMatchers.any())).thenReturn(1000);
    final Portfolio mbean = new Portfolio();
    final ExecutionStartedEvent evt = new ExecutionStartedEvent(Collections.emptyList(), portfolio);
    mbean.handle(evt);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(mbean.getAvailableBalance()).isEqualTo(portfolio.getCzkAvailable());
        softly.assertThat(mbean.getInvestedAmount()).isEqualTo(portfolio.getCzkInvested());
        softly.assertThat(mbean.getLatestUpdatedDateTime()).isBeforeOrEqualTo(OffsetDateTime.now());
        // checks for proper ordering of ratings
        final String[] ratings = Stream.of(Rating.values()).map(Rating::getCode).toArray(String[]::new);
        softly.assertThat(mbean.getInvestedAmountPerRating().keySet()).containsExactly(ratings);
        softly.assertThat(mbean.getRatingShare().keySet()).containsExactly(ratings);
        //checks correct values per rating
        Stream.of(ratings).forEach(r -> {
            softly.assertThat(mbean.getInvestedAmountPerRating()).containsEntry(r, 1000);
            softly.assertThat(mbean.getRatingShare()).containsEntry(r, BigDecimal.ONE);
        });
    });
}
项目:mybatis-dynamic-sql    文件:UpdateStatementTest.java   
@Test
public void testUpdateStatementArithmeticOperation() {
    UpdateStatementProvider updateStatement = update(foo)
            .set(id).incrementBy(1)
            .set(id).decrementBy(2)
            .set(id).multiplyBy(3)
            .set(id).divideBy(4)
            .build()
            .render(RenderingStrategy.MYBATIS3);

    String expectedStatement = "update foo " 
            + "set id = id + 1, "
            + "id = id - 2, "
            + "id = id * 3, "
            + "id = id / 4";

    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(updateStatement.getUpdateStatement()).isEqualTo(expectedStatement);

        softly.assertThat(updateStatement.getParameters().size()).isEqualTo(0);
    });
}
项目:robozonky    文件:OperatingModeTest.java   
@Test
public void defaultTesting() {
    final CommandLine cli = Mockito.mock(CommandLine.class);
    Mockito.when(cli.getTweaksFragment()).thenReturn(Mockito.mock(TweaksCommandLineFragment.class));
    final Investor.Builder builder = new Investor.Builder();
    builder.usingConfirmation(Mockito.mock(ConfirmationProvider.class), new char[0]);
    final Authenticated auth =
            Authenticated.passwordBased(SecretProvider.fallback("user", "pass".toCharArray()));
    final OperatingMode mode = new TestOperatingMode();
    final Optional<InvestmentMode> config = mode.getInvestmentMode(cli, auth, builder);
    Assertions.assertThat(config).isPresent();
    final InvestmentMode result = config.get();
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(result.isFaultTolerant()).isFalse();
        softly.assertThat(result.get()).isEqualTo(ReturnCode.OK);
    });
}
项目:mybatis-dynamic-sql    文件:SelectStatementTest.java   
@Test
public void testOrderBySingleColumnDescending() {
    Date d = new Date();

    SelectStatementProvider selectStatement = select(column1.as("A_COLUMN1"), column2)
            .from(table, "a")
            .where(column1, isEqualTo(d))
            .orderBy(column2.descending())
            .build()
            .render(RenderingStrategy.MYBATIS3);

    SoftAssertions.assertSoftly(softly -> {
        String expectedFullStatement = "select a.column1 as A_COLUMN1, a.column2 "
                + "from foo a "
                + "where a.column1 = #{parameters.p1,jdbcType=DATE} "
                + "order by column2 DESC";

        softly.assertThat(selectStatement.getSelectStatement()).isEqualTo(expectedFullStatement);

        Map<String, Object> parameters = selectStatement.getParameters();
        softly.assertThat(parameters.get("p1")).isEqualTo(d);
    });
}
项目:robozonky    文件:StrategyProviderTest.java   
@Test
public void setAndUnset() {
    final StrategyProvider r = new StrategyProvider();
    r.valueSet(MINIMAL_STRATEGY); // store correct strategy
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(r.getToInvest()).isPresent();
        softly.assertThat(r.getToSell()).isEmpty();
        softly.assertThat(r.getToPurchase()).isPresent();
    });
    r.valueUnset(MINIMAL_STRATEGY);
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(r.getToInvest()).isEmpty();
        softly.assertThat(r.getToSell()).isEmpty();
        softly.assertThat(r.getToPurchase()).isEmpty();
    });
}
项目:mybatis-dynamic-sql    文件:AnimalDataTest.java   
@Test
public void testGreaterThanOrEqualToSubselect() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);

        SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
                .from(animalData, "a")
                .where(brainWeight, isGreaterThanOrEqualTo(select(min(brainWeight)).from(animalData, "b")))
                .build()
                .render(RenderingStrategy.MYBATIS3);

        SoftAssertions.assertSoftly(softly -> {
            softly.assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight >= (select min(b.brain_weight) from AnimalData b)");

            List<AnimalData> records = mapper.selectMany(selectStatement);
            softly.assertThat(records.size()).isEqualTo(65);
        });
    } finally {
        sqlSession.close();
    }
}