Search in sources :

Example 56 with Jedi

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

the class ObjectAssert_isEqualToComparingOnlyGivenFields_Test method comparators_for_fields_should_have_precedence_over_comparators_for_types.

@Test
public void comparators_for_fields_should_have_precedence_over_comparators_for_types() {
    Comparator<String> comparator = (o1, o2) -> o1.compareTo(o2);
    Jedi actual = new Jedi("Yoda", "green");
    Jedi other = new Jedi("Luke", "green");
    assertThat(actual).usingComparatorForFields(ALWAY_EQUALS_STRING, "name").usingComparatorForType(comparator, String.class).isEqualToComparingOnlyGivenFields(other, "name");
}
Also used : EMPTY_MAP(java.util.Collections.EMPTY_MAP) TypeComparators.defaultTypeComparators(org.assertj.core.internal.TypeComparators.defaultTypeComparators) ALWAY_EQUALS_STRING(org.assertj.core.test.AlwaysEqualComparator.ALWAY_EQUALS_STRING) ObjectAssertBaseTest(org.assertj.core.api.ObjectAssertBaseTest) Jedi(org.assertj.core.test.Jedi) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ObjectAssert(org.assertj.core.api.ObjectAssert) Test(org.junit.Test) Comparator(java.util.Comparator) Mockito.verify(org.mockito.Mockito.verify) Jedi(org.assertj.core.test.Jedi) ObjectAssertBaseTest(org.assertj.core.api.ObjectAssertBaseTest) Test(org.junit.Test)

Example 57 with Jedi

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

the class ObjectArrayAssert_hasOnlyOneElementSatisfying_Test method fails_if_arry_has_only_one_element_and_that_element_does_not_statisfy_the_given_assertion.

@Test
public void fails_if_arry_has_only_one_element_and_that_element_does_not_statisfy_the_given_assertion() {
    thrown.expectAssertionError("%nExpecting:%n <\"Yoda\">%nto start with:%n <\"L\">%n");
    Jedi[] jedis = { new Jedi("Yoda", "red") };
    assertThat(jedis).hasOnlyOneElementSatisfying(yoda -> assertThat(yoda.getName()).startsWith("L"));
}
Also used : Jedi(org.assertj.core.test.Jedi) Test(org.junit.Test)

Example 58 with Jedi

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

the class ObjectAssert_isEqualsToComparingFields_Test method should_be_able_to_use_a_date_comparator_for_timestamp.

@Test
public void should_be_able_to_use_a_date_comparator_for_timestamp() {
    JediMaster yoda1 = new JediMaster("Yoda", new Jedi("luke", "Green"));
    yoda1.dateOfBirth = new Timestamp(1000L);
    JediMaster yoda2 = new JediMaster("Yoda", new Jedi("LUKE", null));
    yoda2.dateOfBirth = new Date(1000L);
    // use a date comparator to compare either Date or Timestamp
    assertThat(yoda1).usingComparatorForType(new PersonCaseInsensitiveNameComparator(), Person.class).usingComparatorForType(SYMMETRIC_DATE_COMPARATOR, Date.class).isEqualToComparingFieldByField(yoda2);
    assertThat(yoda2).usingComparatorForType(new PersonCaseInsensitiveNameComparator(), Person.class).usingComparatorForType(SYMMETRIC_DATE_COMPARATOR, Date.class).isEqualToComparingFieldByField(yoda1);
    assertThat(yoda1).usingComparatorForType(new PersonCaseInsensitiveNameComparator(), Person.class).usingComparatorForType(SYMMETRIC_DATE_COMPARATOR, Timestamp.class).isEqualToComparingFieldByField(yoda2);
    assertThat(yoda2).usingComparatorForType(new PersonCaseInsensitiveNameComparator(), Person.class).usingComparatorForType(SYMMETRIC_DATE_COMPARATOR, Timestamp.class).isEqualToComparingFieldByField(yoda1);
}
Also used : Jedi(org.assertj.core.test.Jedi) PersonCaseInsensitiveNameComparator(org.assertj.core.test.PersonCaseInsensitiveNameComparator) Timestamp(java.sql.Timestamp) Date(java.util.Date) Test(org.junit.Test) ObjectAssertBaseTest(org.assertj.core.api.ObjectAssertBaseTest)

Example 59 with Jedi

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

the class ObjectAssert_isEqualsToComparingFields_Test method should_be_able_to_use_a_comparator_for_specified_fields.

@Test
public void should_be_able_to_use_a_comparator_for_specified_fields() {
    Jedi actual = new Jedi("Yoda", "green");
    Jedi other = new Jedi("Luke", "green");
    assertThat(actual).usingComparatorForFields(ALWAY_EQUALS_STRING, "name").isEqualToComparingFieldByField(other);
}
Also used : Jedi(org.assertj.core.test.Jedi) Test(org.junit.Test) ObjectAssertBaseTest(org.assertj.core.api.ObjectAssertBaseTest)

Example 60 with Jedi

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

the class ObjectAssert_returns_Test method perform_assertion_like_users.

@Test
public void perform_assertion_like_users() {
    Jedi yoda = new Jedi("Yoda", "Green");
    assertThat(yoda).returns("Yoda", from(Jedi::getName)).returns("Yoda", Jedi::getName);
}
Also used : Jedi(org.assertj.core.test.Jedi) ObjectAssertBaseTest(org.assertj.core.api.ObjectAssertBaseTest) 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