Search in sources :

Example 1 with ComparisonStrategy

use of org.assertj.core.internal.ComparisonStrategy in project assertj-core by joel-costigliola.

the class ShouldBeEqual_newAssertionError_differentiating_expected_and_actual_Test method should_create_AssertionError_with_message_differentiating_expected_and_actual_persons_even_if_a_comparator_based_comparison_strategy_is_used.

@Test
public void should_create_AssertionError_with_message_differentiating_expected_and_actual_persons_even_if_a_comparator_based_comparison_strategy_is_used() {
    Person actual = new Person("Jake", 43);
    Person expected = new Person("Jake", 47);
    ComparisonStrategy ageComparisonStrategy = new ComparatorBasedComparisonStrategy(new PersonComparator());
    shouldBeEqual = (ShouldBeEqual) shouldBeEqual(actual, expected, ageComparisonStrategy, new StandardRepresentation());
    shouldBeEqual.descriptionFormatter = mock(DescriptionFormatter.class);
    when(shouldBeEqual.descriptionFormatter.format(description)).thenReturn(formattedDescription);
    AssertionError error = shouldBeEqual.newAssertionError(description, new StandardRepresentation());
    assertThat(error).isInstanceOf(AssertionFailedError.class).hasMessage("[my test] %n" + "Expecting:%n" + " <\"Person[name=Jake] (Person@%s)\">%n" + "to be equal to:%n" + " <\"Person[name=Jake] (Person@%s)\">%n" + "when comparing values using PersonComparator%n" + "but was not.", toHexString(actual.hashCode()), toHexString(expected.hashCode()));
}
Also used : StandardRepresentation(org.assertj.core.presentation.StandardRepresentation) ComparisonStrategy(org.assertj.core.internal.ComparisonStrategy) ComparatorBasedComparisonStrategy(org.assertj.core.internal.ComparatorBasedComparisonStrategy) ComparatorBasedComparisonStrategy(org.assertj.core.internal.ComparatorBasedComparisonStrategy) AssertionFailedError(org.opentest4j.AssertionFailedError) Test(org.junit.Test)

Aggregations

ComparatorBasedComparisonStrategy (org.assertj.core.internal.ComparatorBasedComparisonStrategy)1 ComparisonStrategy (org.assertj.core.internal.ComparisonStrategy)1 StandardRepresentation (org.assertj.core.presentation.StandardRepresentation)1 Test (org.junit.Test)1 AssertionFailedError (org.opentest4j.AssertionFailedError)1