Search in sources :

Example 66 with Jedi

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

the class AtomicReferenceArrayAssert_usingFieldByFieldElementComparator_Test method comparators_for_element_field_names_should_have_precedence_over_comparators_for_element_field_types_when_using_field_by_field_element_comparator.

@Test
public void comparators_for_element_field_names_should_have_precedence_over_comparators_for_element_field_types_when_using_field_by_field_element_comparator() {
    Comparator<String> comparator = (o1, o2) -> o1.compareTo(o2);
    Jedi actual = new Jedi("Yoda", "green");
    Jedi other = new Jedi("Luke", "green");
    assertThat(atomicArrayOf(actual)).usingComparatorForElementFieldsWithNames(ALWAY_EQUALS_STRING, "name").usingComparatorForElementFieldsWithType(comparator, String.class).usingFieldByFieldElementComparator().contains(other);
}
Also used : ALWAY_EQUALS_STRING(org.assertj.core.test.AlwaysEqualComparator.ALWAY_EQUALS_STRING) AtomicReferenceArrayAssert(org.assertj.core.api.AtomicReferenceArrayAssert) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Arrays.array(org.assertj.core.util.Arrays.array) String.format(java.lang.String.format) AtomicReferenceArrayElementComparisonStrategy(org.assertj.core.internal.AtomicReferenceArrayElementComparisonStrategy) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) ComparatorBasedComparisonStrategy(org.assertj.core.internal.ComparatorBasedComparisonStrategy) Objects(java.util.Objects) AtomicReferenceArrayAssertBaseTest(org.assertj.core.api.AtomicReferenceArrayAssertBaseTest) Jedi(org.assertj.core.test.Jedi) Comparator(java.util.Comparator) ObjectArrays(org.assertj.core.internal.ObjectArrays) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) Before(org.junit.Before) Jedi(org.assertj.core.test.Jedi) Test(org.junit.Test) AtomicReferenceArrayAssertBaseTest(org.assertj.core.api.AtomicReferenceArrayAssertBaseTest)

Example 67 with Jedi

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

the class AtomicReferenceArrayAssert_usingFieldByFieldElementComparator_Test method should_be_able_to_use_a_comparator_for_specified_fields_of_elements_when_using_field_by_field_element_comparator.

@Test
public void should_be_able_to_use_a_comparator_for_specified_fields_of_elements_when_using_field_by_field_element_comparator() {
    Jedi actual = new Jedi("Yoda", "green");
    Jedi other = new Jedi("Luke", "green");
    assertThat(atomicArrayOf(actual)).usingComparatorForElementFieldsWithNames(ALWAY_EQUALS_STRING, "name").usingFieldByFieldElementComparator().contains(other);
}
Also used : Jedi(org.assertj.core.test.Jedi) Test(org.junit.Test) AtomicReferenceArrayAssertBaseTest(org.assertj.core.api.AtomicReferenceArrayAssertBaseTest)

Example 68 with Jedi

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

the class Objects_assertHasSameHashCodeAs_Test method should_fail_if_actual_does_not_have_the_same_hash_code_as_other.

@Test
public void should_fail_if_actual_does_not_have_the_same_hash_code_as_other() {
    AssertionInfo info = someInfo();
    // Jedi class hashCode is computed with the Jedi's name only
    Jedi luke = new Jedi("Luke", "green");
    try {
        objects.assertHasSameHashCodeAs(info, greenYoda, luke);
        failBecauseExpectedAssertionErrorWasNotThrown();
    } catch (AssertionError err) {
        verify(failures).failure(info, shouldHaveSameHashCode(greenYoda, luke));
    }
}
Also used : AssertionInfo(org.assertj.core.api.AssertionInfo) Jedi(org.assertj.core.test.Jedi) ObjectsBaseTest(org.assertj.core.internal.ObjectsBaseTest) Test(org.junit.Test)

Example 69 with Jedi

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

the class Objects_assertIsEqualToComparingOnlyGivenFields_Test method should_pass_even_if_non_accepted_fields_differ.

@Test
public void should_pass_even_if_non_accepted_fields_differ() {
    Jedi actual = new Jedi("Yoda", "Green");
    Jedi other = new Jedi("Yoda", "Blue");
    objects.assertIsEqualToComparingOnlyGivenFields(someInfo(), actual, other, noFieldComparators(), defaultTypeComparators(), "name");
}
Also used : Jedi(org.assertj.core.test.Jedi) ObjectsBaseTest(org.assertj.core.internal.ObjectsBaseTest) Test(org.junit.Test)

Example 70 with Jedi

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

the class Objects_assertIsEqualToComparingOnlyGivenFields_Test method should_fail_if_actual_is_null.

@Test
public void should_fail_if_actual_is_null() {
    thrown.expectAssertionError(actualIsNull());
    Jedi other = new Jedi("Yoda", "Green");
    objects.assertIsEqualToComparingOnlyGivenFields(someInfo(), null, other, noFieldComparators(), defaultTypeComparators(), "name", "lightSaberColor");
}
Also used : Jedi(org.assertj.core.test.Jedi) ObjectsBaseTest(org.assertj.core.internal.ObjectsBaseTest) 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