Search in sources :

Example 96 with Jedi

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

the class ObjectArrayAssert_usingFieldByFieldElementComparator_Test method should_be_able_to_use_a_comparator_for_element_fields_with_specified_type_when_using_field_by_field_element_comparator.

@Test
public void should_be_able_to_use_a_comparator_for_element_fields_with_specified_type_when_using_field_by_field_element_comparator() {
    Jedi actual = new Jedi("Yoda", "green");
    Jedi other = new Jedi("Luke", "blue");
    assertThat(array(actual)).usingComparatorForElementFieldsWithType(ALWAY_EQUALS_STRING, String.class).usingFieldByFieldElementComparator().contains(other);
}
Also used : Jedi(org.assertj.core.test.Jedi) Test(org.junit.Test) ObjectArrayAssertBaseTest(org.assertj.core.api.ObjectArrayAssertBaseTest)

Example 97 with Jedi

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

the class ObjectArrayAssert_usingFieldByFieldElementComparator_Test method comparators_for_element_field_names_should_have_precedence_over_comparators_for_element_field_types_when_using_field_by_field_element_comparator.

@Test
public void comparators_for_element_field_names_should_have_precedence_over_comparators_for_element_field_types_when_using_field_by_field_element_comparator() {
    Comparator<String> comparator = (o1, o2) -> o1.compareTo(o2);
    Jedi actual = new Jedi("Yoda", "green");
    Jedi other = new Jedi("Luke", "green");
    assertThat(array(actual)).usingComparatorForElementFieldsWithNames(ALWAY_EQUALS_STRING, "name").usingComparatorForElementFieldsWithType(comparator, String.class).usingFieldByFieldElementComparator().contains(other);
}
Also used : ObjectArrayElementComparisonStrategy(org.assertj.core.internal.ObjectArrayElementComparisonStrategy) ALWAY_EQUALS_STRING(org.assertj.core.test.AlwaysEqualComparator.ALWAY_EQUALS_STRING) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Arrays.array(org.assertj.core.util.Arrays.array) ObjectArrayAssert(org.assertj.core.api.ObjectArrayAssert) ComparatorBasedComparisonStrategy(org.assertj.core.internal.ComparatorBasedComparisonStrategy) Objects(java.util.Objects) ObjectArrayAssertBaseTest(org.assertj.core.api.ObjectArrayAssertBaseTest) Jedi(org.assertj.core.test.Jedi) Comparator(java.util.Comparator) ObjectArrays(org.assertj.core.internal.ObjectArrays) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) Before(org.junit.Before) Jedi(org.assertj.core.test.Jedi) Test(org.junit.Test) ObjectArrayAssertBaseTest(org.assertj.core.api.ObjectArrayAssertBaseTest)

Example 98 with Jedi

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

the class ExtendedByTypesComparator_compareTo_Test method should_return_equal_if_objects_are_equal_by_default_comparator.

@Test
public void should_return_equal_if_objects_are_equal_by_default_comparator() {
    assertThat(EXTENDED_STANDARD_COMPARATOR.compare(new Jedi("Yoda", "Green"), new Jedi("Yoda", "Green"))).isZero();
    assertThat(EXTENDED_FIELD_BY_FIELD_COMPARATOR.compare(new Jedi("Yoda", "Green"), new Jedi("Yoda", "Green"))).isZero();
}
Also used : Jedi(org.assertj.core.test.Jedi) Test(org.junit.Test)

Example 99 with Jedi

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

the class ShouldBeEqualByComparingFieldByFieldRecursively_create_Test method should_throw_assertion_error_rather_than_null_pointer_when_one_nested_member_is_null.

@Test
public void should_throw_assertion_error_rather_than_null_pointer_when_one_nested_member_is_null() {
    // GIVEN
    Jedi yoda = new Jedi("Yoda", "Green");
    Jedi noname = new Jedi(null, "Green");
    // WHEN
    Throwable throwable1 = catchThrowable(() -> assertThat(yoda).isEqualToComparingFieldByFieldRecursively(noname));
    Throwable throwable2 = catchThrowable(() -> assertThat(noname).isEqualToComparingFieldByFieldRecursively(yoda));
    // THEN
    assertThat(throwable1).isInstanceOf(AssertionError.class).isNotInstanceOf(NullPointerException.class);
    assertThat(throwable2).isInstanceOf(AssertionError.class).isNotInstanceOf(NullPointerException.class);
}
Also used : Jedi(org.assertj.core.test.Jedi) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test)

Example 100 with Jedi

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

the class ShouldBeEqualComparingOnlyGivenFields_create_Test method should_create_error_message_with_all_fields_differences.

@Test
public void should_create_error_message_with_all_fields_differences() {
    factory = shouldBeEqualComparingOnlyGivenFields(new Jedi("Luke", "blue"), newArrayList("name", "lightSaberColor"), newArrayList((Object) "Luke", "blue"), newArrayList((Object) "Yoda", "green"), newArrayList("name", "lightSaberColor"));
    String message = factory.create(new TextDescription("Test"), new StandardRepresentation());
    assertThat(message).isEqualTo(String.format("[Test] %n" + "Expecting values:%n" + "  <[\"Yoda\", \"green\"]>%n" + "in fields:%n" + "  <[\"name\", \"lightSaberColor\"]>%n" + "but were:%n" + "  <[\"Luke\", \"blue\"]>%n" + "in <Luke the Jedi>.%n" + "Comparison was performed on fields:%n" + "  <[\"name\", \"lightSaberColor\"]>"));
}
Also used : Jedi(org.assertj.core.test.Jedi) TextDescription(org.assertj.core.description.TextDescription) StandardRepresentation(org.assertj.core.presentation.StandardRepresentation) 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