Search in sources :

Example 16 with TextDescription

use of org.assertj.core.description.TextDescription in project assertj-core by joel-costigliola.

the class ShouldBeEqualByComparingFieldByFieldRecursively_create_Test method should_precise_missing_fields_when_actual_does_not_declare_all_expected_fields.

@Test
public void should_precise_missing_fields_when_actual_does_not_declare_all_expected_fields() {
    // GIVEN
    Person person = new Person("John", "Doe");
    PersonDAO personDAO = new PersonDAO("John", "Doe", 1L, 23);
    // THEN
    List<Difference> differences = determineDifferences(person, personDAO, null, null);
    // WHEN
    // @format:off
    String message = shouldBeEqualByComparingFieldByFieldRecursive(person, personDAO, differences, REPRESENTATION).create(new TextDescription("Test"), REPRESENTATION);
    // @format:on
    // THEN
    String personHash = toHexString(person.hashCode());
    String personDAOHash = toHexString(personDAO.hashCode());
    assertThat(message).isEqualTo(format("[Test] %n" + "Expecting:%n" + "  <org.assertj.core.error.Person@%s>%n" + "to be equal to:%n" + "  <org.assertj.core.error.PersonDAO@%s>%n" + "when recursively comparing field by field, but found the following difference(s):%n" + "%n" + "Path to difference: <>%n" + "- actual  : <org.assertj.core.error.Person@%s>%n" + "- expected: <org.assertj.core.error.PersonDAO@%s>%n" + "- reason  : org.assertj.core.error.Person can't be compared to org.assertj.core.error.PersonDAO as PersonDAO does not declare all Person fields, it lacks these:[firstName, lastName]", personHash, personDAOHash, personHash, personDAOHash));
}
Also used : TextDescription(org.assertj.core.description.TextDescription) Difference(org.assertj.core.internal.DeepDifference.Difference) Integer.toHexString(java.lang.Integer.toHexString) Test(org.junit.Test)

Example 17 with TextDescription

use of org.assertj.core.description.TextDescription 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 18 with TextDescription

use of org.assertj.core.description.TextDescription 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 19 with TextDescription

use of org.assertj.core.description.TextDescription in project assertj-core by joel-costigliola.

the class ShouldBeInSameDay_create_Test method should_create_error_message.

@Test
public void should_create_error_message() {
    ErrorMessageFactory factory = shouldBeInSameDay(parse("2010-01-01"), parse("2010-01-25"));
    String message = factory.create(new TextDescription("Test"), new StandardRepresentation());
    assertThat(message).isEqualTo(format("[Test] %n" + "Expecting:%n" + " <2010-01-01T00:00:00.000>%n" + "to be on same year, month and day as:%n" + " <2010-01-25T00:00:00.000>"));
}
Also used : TextDescription(org.assertj.core.description.TextDescription) StandardRepresentation(org.assertj.core.presentation.StandardRepresentation) Test(org.junit.Test)

Example 20 with TextDescription

use of org.assertj.core.description.TextDescription in project assertj-core by joel-costigliola.

the class ShouldBeInSameMonth_create_Test method should_create_error_message.

@Test
public void should_create_error_message() {
    ErrorMessageFactory factory = shouldBeInSameMonth(parse("2010-01-01"), parse("2010-02-01"));
    String message = factory.create(new TextDescription("Test"), new StandardRepresentation());
    assertThat(message).isEqualTo(format("[Test] %n" + "Expecting:%n" + " <2010-01-01T00:00:00.000>%n" + "to be on same year and month as:%n" + " <2010-02-01T00:00:00.000>"));
}
Also used : TextDescription(org.assertj.core.description.TextDescription) StandardRepresentation(org.assertj.core.presentation.StandardRepresentation) Test(org.junit.Test)

Aggregations

TextDescription (org.assertj.core.description.TextDescription)210 Test (org.junit.Test)210 StandardRepresentation (org.assertj.core.presentation.StandardRepresentation)157 ComparatorBasedComparisonStrategy (org.assertj.core.internal.ComparatorBasedComparisonStrategy)24 PredicateDescription (org.assertj.core.presentation.PredicateDescription)8 Jedi (org.assertj.core.test.Jedi)6 Path (java.nio.file.Path)4 Integer.toHexString (java.lang.Integer.toHexString)3 Date (java.util.Date)3 Description (org.assertj.core.description.Description)3 Difference (org.assertj.core.internal.DeepDifference.Difference)3 BaseTest (org.assertj.core.api.BaseTest)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 LongPredicate (java.util.function.LongPredicate)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 LongStream (java.util.stream.LongStream)1