Search in sources :

Example 31 with Jedi

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

the class ObjectAssert_isEqualsToComparingFields_Test method should_be_able_to_use_a_comparator_for_specified_type.

@Test
public void should_be_able_to_use_a_comparator_for_specified_type() {
    Jedi actual = new Jedi("Yoda", "green");
    Jedi other = new Jedi("Luke", "blue");
    assertThat(actual).usingComparatorForType(ALWAY_EQUALS_STRING, String.class).isEqualToComparingFieldByField(other);
}
Also used : Jedi(org.assertj.core.test.Jedi) Test(org.junit.Test) ObjectAssertBaseTest(org.assertj.core.api.ObjectAssertBaseTest)

Example 32 with Jedi

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

the class ObjectAssert_isEqualsToComparingFields_Test method should_be_able_to_use_a_type_comparator_for_any_of_the_type_subclasses.

@Test
public void should_be_able_to_use_a_type_comparator_for_any_of_the_type_subclasses() {
    JediMaster yoda1 = new JediMaster("Yoda", new Jedi("luke", "Green"));
    JediMaster yoda2 = new JediMaster("Yoda", new Jedi("LUKE", null));
    // Jedi is a subclass of Person
    assertThat(yoda1).usingComparatorForType(new PersonCaseInsensitiveNameComparator(), Person.class).isEqualToComparingFieldByField(yoda2);
    assertThat(yoda2).usingComparatorForType(new PersonCaseInsensitiveNameComparator(), Person.class).isEqualToComparingFieldByField(yoda1);
}
Also used : Jedi(org.assertj.core.test.Jedi) PersonCaseInsensitiveNameComparator(org.assertj.core.test.PersonCaseInsensitiveNameComparator) Person(org.assertj.core.test.Person) Test(org.junit.Test) ObjectAssertBaseTest(org.assertj.core.api.ObjectAssertBaseTest)

Example 33 with Jedi

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

the class ObjectArrayAssert_hasOnlyOneElementSatisfying_Test method fails_if_arry_has_more_than_one_element.

@Test
public void fails_if_arry_has_more_than_one_element() {
    thrown.expectAssertionErrorWithMessageContaining("Expected size:<1> but was:<2>");
    Jedi[] jedis = { 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 34 with Jedi

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

the class ObjectArrayAssert_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");
    Jedi[] jedis = { 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 35 with Jedi

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

the class ObjectArrayAssert_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() {
    Jedi[] jedis = { 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)

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