Search in sources :

Example 11 with Jedi

use of org.assertj.core.test.Jedi in project assertj-core by joel-costigliola.

the class IterableAssert_hasOnlyOneElementSatisfying_Test method succeeds_if_iterable_has_only_one_element_and_that_element_statisfies_the_given_assertions.

@Test
public void succeeds_if_iterable_has_only_one_element_and_that_element_statisfies_the_given_assertions() {
    assertThat(asList(new Jedi("Yoda", "red"))).hasOnlyOneElementSatisfying(yoda -> {
        assertThat(yoda.getName()).isEqualTo("Yoda");
        assertThat(yoda.lightSaberColor).isEqualTo("red");
    });
}
Also used : Jedi(org.assertj.core.test.Jedi) Test(org.junit.Test)

Example 12 with Jedi

use of org.assertj.core.test.Jedi in project assertj-core by joel-costigliola.

the class IterableAssert_hasOnlyOneElementSatisfying_Test method fails_if_iterable_has_only_one_element_and_that_element_does_not_statisfy_the_soft_assertion.

@Test
public void fails_if_iterable_has_only_one_element_and_that_element_does_not_statisfy_the_soft_assertion() {
    List<Jedi> jedis = asList(new Jedi("Yoda", "red"));
    Throwable assertionError = catchThrowable(() -> {
        assertThat(jedis).hasOnlyOneElementSatisfying(yoda -> {
            SoftAssertions softly = new SoftAssertions();
            softly.assertThat(yoda.getName()).startsWith("L");
            softly.assertThat(yoda.getName()).startsWith("M");
            softly.assertAll();
        });
    });
    assertThat(assertionError).hasMessageContaining(format("Expecting:%n <\"Yoda\">%nto start with:%n <\"L\">")).hasMessageContaining(format("Expecting:%n <\"Yoda\">%nto start with:%n <\"M\">"));
}
Also used : Jedi(org.assertj.core.test.Jedi) SoftAssertions(org.assertj.core.api.SoftAssertions) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test)

Example 13 with Jedi

use of org.assertj.core.test.Jedi in project assertj-core by joel-costigliola.

the class IterableAssert_hasOnlyOneElementSatisfying_Test method fails_if_iterable_has_more_than_one_element.

@Test
public void fails_if_iterable_has_more_than_one_element() {
    thrown.expectAssertionErrorWithMessageContaining("Expected size:<1> but was:<2>");
    List<Jedi> jedis = asList(new Jedi("Yoda", "red"), new Jedi("Luke", "green"));
    assertThat(jedis).hasOnlyOneElementSatisfying(yoda -> assertThat(yoda.getName()).startsWith("Y"));
}
Also used : Jedi(org.assertj.core.test.Jedi) Test(org.junit.Test)

Example 14 with Jedi

use of org.assertj.core.test.Jedi in project assertj-core by joel-costigliola.

the class IterableAssert_hasOnlyOneElementSatisfying_Test method fails_if_iterable_has_only_one_element_and_that_element_does_not_statisfy_one_of_the_given_assertion.

@Test
public void fails_if_iterable_has_only_one_element_and_that_element_does_not_statisfy_one_of_the_given_assertion() {
    thrown.expectAssertionError("%nExpecting:%n <\"Yoda\">%nto start with:%n <\"L\">%n");
    List<Jedi> jedis = asList(new Jedi("Yoda", "red"));
    assertThat(jedis).hasOnlyOneElementSatisfying(yoda -> {
        assertThat(yoda.getName()).startsWith("Y");
        assertThat(yoda.getName()).startsWith("L");
    });
}
Also used : Jedi(org.assertj.core.test.Jedi) Test(org.junit.Test)

Example 15 with Jedi

use of org.assertj.core.test.Jedi in project assertj-core by joel-costigliola.

the class AbstractAssert_satisfies_Test method setup.

@Before
public void setup() {
    yoda = new Jedi("Yoda", "Green");
    luke = new Jedi("Luke Skywalker", "Green");
    jediRequirements = jedi -> {
        assertThat(jedi.lightSaberColor).as("check light saber").isEqualTo("Green");
        assertThat(jedi.getName()).as("check name").doesNotContain("Dark");
    };
}
Also used : Jedi(org.assertj.core.test.Jedi) Before(org.junit.Before)

Aggregations

Jedi (org.assertj.core.test.Jedi)108 Test (org.junit.Test)104 ObjectsBaseTest (org.assertj.core.internal.ObjectsBaseTest)30 ObjectAssertBaseTest (org.assertj.core.api.ObjectAssertBaseTest)26 Comparator (java.util.Comparator)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 ALWAY_EQUALS_STRING (org.assertj.core.test.AlwaysEqualComparator.ALWAY_EQUALS_STRING)13 Before (org.junit.Before)13 AssertionInfo (org.assertj.core.api.AssertionInfo)10 AtomicReferenceArrayAssertBaseTest (org.assertj.core.api.AtomicReferenceArrayAssertBaseTest)9 IterableAssertBaseTest (org.assertj.core.api.IterableAssertBaseTest)9 ObjectArrayAssertBaseTest (org.assertj.core.api.ObjectArrayAssertBaseTest)9 ComparatorBasedComparisonStrategy (org.assertj.core.internal.ComparatorBasedComparisonStrategy)9 Lists.newArrayList (org.assertj.core.util.Lists.newArrayList)7 TextDescription (org.assertj.core.description.TextDescription)6 ExtendedByTypesComparator (org.assertj.core.internal.ExtendedByTypesComparator)6 ObjectArrays (org.assertj.core.internal.ObjectArrays)6 StandardRepresentation (org.assertj.core.presentation.StandardRepresentation)6 List (java.util.List)5 TypeComparators.defaultTypeComparators (org.assertj.core.internal.TypeComparators.defaultTypeComparators)5