Search in sources :

Example 1 with StandardRepresentation

use of org.assertj.core.presentation.StandardRepresentation in project gwt-test-utils by gwt-test-utils.

the class GwtGenericAssert method propertyComparisonFailed.

/**
     * Returns a <code>{@link AssertionError}</code> describing a property comparison failure. A
     * default description is set if the default error message is not overrided and a custom
     * description is not applied. In both case, the resulting description would be prefixed by the
     * message eventually supplied through {@link GwtGenericAssert#withPrefix(String)}.
     *
     * @param propertyName the compared property name
     * @param actual       the actual value.
     * @param expected     the expected value.
     * @return a {@code AssertionError} describing the comparison failure.
     */
protected AssertionError propertyComparisonFailed(String propertyName, Object actual, Object expected) {
    GwtWritableAssertionInfo info = new GwtWritableAssertionInfo();
    info.prefix(gwtInfo.prefix());
    info.overridingErrorMessage(gwtInfo.overridingErrorMessage());
    Description d = gwtInfo.superDescription();
    String newDescription = d != null ? d.value() + " " + propertyName : this.actual.getClass().getSimpleName() + "'s " + propertyName;
    info.description(newDescription);
    return failures.failure(info, shouldBeEqual(actual, expected, new StandardRepresentation()));
}
Also used : Description(org.assertj.core.description.Description) StandardRepresentation(org.assertj.core.presentation.StandardRepresentation)

Example 2 with StandardRepresentation

use of org.assertj.core.presentation.StandardRepresentation 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)

Example 3 with StandardRepresentation

use of org.assertj.core.presentation.StandardRepresentation in project assertj-core by joel-costigliola.

the class ShouldBeEqual_newAssertionError_differentiating_expected_and_actual_Test method should_create_AssertionError_with_message_differentiating_null_and_object_with_null_toString.

@Test
public void should_create_AssertionError_with_message_differentiating_null_and_object_with_null_toString() {
    Object actual = null;
    Object expected = new ToStringIsNull();
    shouldBeEqual = (ShouldBeEqual) shouldBeEqual(actual, expected, 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" + " <null>%n" + "to be equal to:%n" + " <\"null (ToStringIsNull@%s)\">%n" + "but was not.", toHexString(expected.hashCode()));
}
Also used : StandardRepresentation(org.assertj.core.presentation.StandardRepresentation) AssertionFailedError(org.opentest4j.AssertionFailedError) Test(org.junit.Test)

Example 4 with StandardRepresentation

use of org.assertj.core.presentation.StandardRepresentation in project assertj-core by joel-costigliola.

the class ShouldBeEqual_newAssertionError_differentiating_expected_and_actual_Test method should_create_AssertionError_with_message_differentiating_expected_double_and_actual_float.

@Test
public void should_create_AssertionError_with_message_differentiating_expected_double_and_actual_float() {
    Float actual = 42f;
    Double expected = 42d;
    shouldBeEqual = (ShouldBeEqual) shouldBeEqual(actual, expected, new StandardRepresentation());
    shouldBeEqual.descriptionFormatter = mock(DescriptionFormatter.class);
    when(shouldBeEqual.descriptionFormatter.format(description)).thenReturn(formattedDescription);
    AssertionError error = shouldBeEqual.newAssertionError(description, new StandardRepresentation());
    assertThat(error).isInstanceOf(ComparisonFailure.class).hasMessage("[my test] expected:<42.0[]> but was:<42.0[f]>");
}
Also used : ComparisonFailure(org.junit.ComparisonFailure) StandardRepresentation(org.assertj.core.presentation.StandardRepresentation) Test(org.junit.Test)

Example 5 with StandardRepresentation

use of org.assertj.core.presentation.StandardRepresentation in project assertj-core by joel-costigliola.

the class ShouldBeEqual_newAssertionError_differentiating_expected_and_actual_Test method should_create_AssertionError_with_message_differentiating_object_with_null_toString_and_null.

@Test
public void should_create_AssertionError_with_message_differentiating_object_with_null_toString_and_null() {
    Object actual = new ToStringIsNull();
    Object expected = null;
    shouldBeEqual = (ShouldBeEqual) shouldBeEqual(actual, expected, 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" + " <\"null (ToStringIsNull@%s)\">%n" + "to be equal to:%n" + " <null>%n" + "but was not.", toHexString(actual.hashCode()));
}
Also used : StandardRepresentation(org.assertj.core.presentation.StandardRepresentation) AssertionFailedError(org.opentest4j.AssertionFailedError) Test(org.junit.Test)

Aggregations

StandardRepresentation (org.assertj.core.presentation.StandardRepresentation)241 Test (org.junit.Test)216 TextDescription (org.assertj.core.description.TextDescription)157 TestDescription (org.assertj.core.internal.TestDescription)48 ComparatorBasedComparisonStrategy (org.assertj.core.internal.ComparatorBasedComparisonStrategy)22 AssertionInfo (org.assertj.core.api.AssertionInfo)10 Before (org.junit.Before)9 PredicateDescription (org.assertj.core.presentation.PredicateDescription)7 Jedi (org.assertj.core.test.Jedi)6 Path (java.nio.file.Path)5 AssertionFailedError (org.opentest4j.AssertionFailedError)4 Date (java.util.Date)3 BaseTest (org.assertj.core.api.BaseTest)2 Description (org.assertj.core.description.Description)2 BigDecimalsBaseTest (org.assertj.core.internal.BigDecimalsBaseTest)2 BigIntegersBaseTest (org.assertj.core.internal.BigIntegersBaseTest)2 ComparisonFailure (org.junit.ComparisonFailure)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1