Search in sources :

Example 1 with Jedi

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

the class ShouldBeEqualIgnoringGivenFields_create_Test method should_create_error_message_with_single_field_difference.

@Test
public void should_create_error_message_with_single_field_difference() {
    factory = shouldBeEqualToIgnoringGivenFields(new Jedi("Yoda", "blue"), newArrayList("lightSaberColor"), newArrayList((Object) "blue"), newArrayList((Object) "green"), newArrayList("someIgnoredField"));
    String message = factory.create(new TextDescription("Test"), new StandardRepresentation());
    assertThat(message).isEqualTo(String.format("[Test] %n" + "Expecting value <\"green\"> in field <\"lightSaberColor\"> " + "but was <\"blue\"> in <Yoda the Jedi>.%n" + "Comparison was performed on all fields but <[\"someIgnoredField\"]>"));
}
Also used : Jedi(org.assertj.core.test.Jedi) TextDescription(org.assertj.core.description.TextDescription) StandardRepresentation(org.assertj.core.presentation.StandardRepresentation) Test(org.junit.Test)

Example 2 with Jedi

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

the class ShouldBeEqualIgnoringGivenFields_create_Test method should_create_error_message_with_all_fields_differences.

@Test
public void should_create_error_message_with_all_fields_differences() {
    factory = shouldBeEqualToIgnoringGivenFields(new Jedi("Yoda", "blue"), newArrayList("name", "lightSaberColor"), newArrayList((Object) "Yoda", "blue"), newArrayList((Object) "Yoda", "green"), newArrayList("someIgnoredField"));
    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" + "  <[\"Yoda\", \"blue\"]>%n" + "in <Yoda the Jedi>.%n" + "Comparison was performed on all fields but <[\"someIgnoredField\"]>"));
}
Also used : Jedi(org.assertj.core.test.Jedi) TextDescription(org.assertj.core.description.TextDescription) StandardRepresentation(org.assertj.core.presentation.StandardRepresentation) Test(org.junit.Test)

Example 3 with Jedi

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

the class ThrowableAssert_built_from_lambda_Test method should_build_ThrowableAssert_with_checked_exception_thrown_by_lambda.

@Test
public void should_build_ThrowableAssert_with_checked_exception_thrown_by_lambda() {
    Jedi yoda = new Jedi("Yoda", "Green");
    // @format:off
    assertThatThrownBy(() -> {
        throw new Exception(yoda + " is no Sith");
    }).isInstanceOf(Exception.class).hasMessage(yoda + " is no Sith");
// @format:on
}
Also used : Jedi(org.assertj.core.test.Jedi) ExpectedException(org.assertj.core.test.ExpectedException) Test(org.junit.Test)

Example 4 with Jedi

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

the class ExtendedByTypesComparator_compareTo_Test method should_return_are_not_equal_if_objects_are_not_equal_by_default_comparator.

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

Example 5 with Jedi

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

the class IterableAssert_usingElementComparatorIgnoringFields_Test method comparators_for_element_field_names_should_have_precedence_over_comparators_for_element_field_types_using_element_comparator_ignoring_fields.

@Test
public void comparators_for_element_field_names_should_have_precedence_over_comparators_for_element_field_types_using_element_comparator_ignoring_fields() {
    Comparator<String> comparator = (o1, o2) -> o1.compareTo(o2);
    Jedi actual = new Jedi("Yoda", "green");
    Jedi other = new Jedi("Luke", "green");
    assertThat(singletonList(actual)).usingComparatorForElementFieldsWithNames(ALWAY_EQUALS_STRING, "name").usingComparatorForElementFieldsWithType(comparator, String.class).usingElementComparatorIgnoringFields("lightSaberColor").contains(other);
}
Also used : Iterables(org.assertj.core.internal.Iterables) ALWAY_EQUALS_STRING(org.assertj.core.test.AlwaysEqualComparator.ALWAY_EQUALS_STRING) ExtendedByTypesComparator(org.assertj.core.internal.ExtendedByTypesComparator) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConcreteIterableAssert(org.assertj.core.api.ConcreteIterableAssert) IgnoringFieldsComparator(org.assertj.core.internal.IgnoringFieldsComparator) Test(org.junit.Test) Collections.singletonList(java.util.Collections.singletonList) ComparatorBasedComparisonStrategy(org.assertj.core.internal.ComparatorBasedComparisonStrategy) IterableAssertBaseTest(org.assertj.core.api.IterableAssertBaseTest) Jedi(org.assertj.core.test.Jedi) Comparator(java.util.Comparator) Before(org.junit.Before) Jedi(org.assertj.core.test.Jedi) Test(org.junit.Test) IterableAssertBaseTest(org.assertj.core.api.IterableAssertBaseTest)

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