Search in sources :

Example 1 with ALWAY_EQUALS_STRING

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

the class IterableAssert_usingElementComparatorIgnoringFields_Test method comparators_for_element_field_names_should_have_precedence_over_comparators_for_element_field_types_using_element_comparator_ignoring_fields.

@Test
public void comparators_for_element_field_names_should_have_precedence_over_comparators_for_element_field_types_using_element_comparator_ignoring_fields() {
    Comparator<String> comparator = (o1, o2) -> o1.compareTo(o2);
    Jedi actual = new Jedi("Yoda", "green");
    Jedi other = new Jedi("Luke", "green");
    assertThat(singletonList(actual)).usingComparatorForElementFieldsWithNames(ALWAY_EQUALS_STRING, "name").usingComparatorForElementFieldsWithType(comparator, String.class).usingElementComparatorIgnoringFields("lightSaberColor").contains(other);
}
Also used : Iterables(org.assertj.core.internal.Iterables) ALWAY_EQUALS_STRING(org.assertj.core.test.AlwaysEqualComparator.ALWAY_EQUALS_STRING) ExtendedByTypesComparator(org.assertj.core.internal.ExtendedByTypesComparator) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConcreteIterableAssert(org.assertj.core.api.ConcreteIterableAssert) IgnoringFieldsComparator(org.assertj.core.internal.IgnoringFieldsComparator) Test(org.junit.Test) Collections.singletonList(java.util.Collections.singletonList) ComparatorBasedComparisonStrategy(org.assertj.core.internal.ComparatorBasedComparisonStrategy) IterableAssertBaseTest(org.assertj.core.api.IterableAssertBaseTest) Jedi(org.assertj.core.test.Jedi) Comparator(java.util.Comparator) Before(org.junit.Before) Jedi(org.assertj.core.test.Jedi) Test(org.junit.Test) IterableAssertBaseTest(org.assertj.core.api.IterableAssertBaseTest)

Example 2 with ALWAY_EQUALS_STRING

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

the class IterableAssert_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(singletonList(actual)).usingComparatorForElementFieldsWithNames(ALWAY_EQUALS_STRING, "name").usingComparatorForElementFieldsWithType(comparator, String.class).usingFieldByFieldElementComparator().contains(other);
}
Also used : Iterables(org.assertj.core.internal.Iterables) ALWAY_EQUALS_STRING(org.assertj.core.test.AlwaysEqualComparator.ALWAY_EQUALS_STRING) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConcreteIterableAssert(org.assertj.core.api.ConcreteIterableAssert) Test(org.junit.Test) IterableElementComparisonStrategy(org.assertj.core.internal.IterableElementComparisonStrategy) Collections.singletonList(java.util.Collections.singletonList) ComparatorBasedComparisonStrategy(org.assertj.core.internal.ComparatorBasedComparisonStrategy) Objects(java.util.Objects) List(java.util.List) IterableAssertBaseTest(org.assertj.core.api.IterableAssertBaseTest) Arrays.asList(java.util.Arrays.asList) Jedi(org.assertj.core.test.Jedi) Comparator(java.util.Comparator) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) Before(org.junit.Before) Jedi(org.assertj.core.test.Jedi) Test(org.junit.Test) IterableAssertBaseTest(org.assertj.core.api.IterableAssertBaseTest)

Example 3 with ALWAY_EQUALS_STRING

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

the class ObjectAssert_isEqualToIgnoringGivenFields_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).isEqualToIgnoringGivenFields(other, "lightSaberColor");
}
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 4 with ALWAY_EQUALS_STRING

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

the class ObjectArrayAssert_usingElementComparatorOnFields_Test method comparators_for_element_field_names_should_have_precedence_over_comparators_for_element_field_types_using_element_comparator_on_fields.

@Test
public void comparators_for_element_field_names_should_have_precedence_over_comparators_for_element_field_types_using_element_comparator_on_fields() {
    Comparator<String> comparator = (o1, o2) -> o1.compareTo(o2);
    Jedi actual = new Jedi("Yoda", "green");
    Jedi other = new Jedi("Luke", "green");
    assertThat(array(actual)).usingComparatorForElementFieldsWithNames(ALWAY_EQUALS_STRING, "name").usingComparatorForElementFieldsWithType(comparator, String.class).usingElementComparatorOnFields("name", "lightSaberColor").contains(other);
}
Also used : OnFieldsComparator(org.assertj.core.internal.OnFieldsComparator) ALWAY_EQUALS_STRING(org.assertj.core.test.AlwaysEqualComparator.ALWAY_EQUALS_STRING) ExtendedByTypesComparator(org.assertj.core.internal.ExtendedByTypesComparator) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Arrays.array(org.assertj.core.util.Arrays.array) ObjectArrayAssert(org.assertj.core.api.ObjectArrayAssert) ComparatorBasedComparisonStrategy(org.assertj.core.internal.ComparatorBasedComparisonStrategy) ObjectArrayAssertBaseTest(org.assertj.core.api.ObjectArrayAssertBaseTest) Jedi(org.assertj.core.test.Jedi) Comparator(java.util.Comparator) ObjectArrays(org.assertj.core.internal.ObjectArrays) Before(org.junit.Before) Jedi(org.assertj.core.test.Jedi) Test(org.junit.Test) ObjectArrayAssertBaseTest(org.assertj.core.api.ObjectArrayAssertBaseTest)

Example 5 with ALWAY_EQUALS_STRING

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

the class ObjectAssert_isEqualToIgnoringNullFields_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", null);
    Jedi other = new Jedi("Luke", null);
    assertThat(actual).usingComparatorForFields(ALWAY_EQUALS_STRING, "name").usingComparatorForType(comparator, String.class).isEqualToIgnoringNullFields(other);
}
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)

Aggregations

Comparator (java.util.Comparator)13 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 ALWAY_EQUALS_STRING (org.assertj.core.test.AlwaysEqualComparator.ALWAY_EQUALS_STRING)13 Jedi (org.assertj.core.test.Jedi)13 Test (org.junit.Test)13 ComparatorBasedComparisonStrategy (org.assertj.core.internal.ComparatorBasedComparisonStrategy)9 Before (org.junit.Before)9 ExtendedByTypesComparator (org.assertj.core.internal.ExtendedByTypesComparator)6 ObjectArrays (org.assertj.core.internal.ObjectArrays)6 EMPTY_MAP (java.util.Collections.EMPTY_MAP)4 ObjectAssert (org.assertj.core.api.ObjectAssert)4 ObjectAssertBaseTest (org.assertj.core.api.ObjectAssertBaseTest)4 TypeComparators.defaultTypeComparators (org.assertj.core.internal.TypeComparators.defaultTypeComparators)4 Arrays.array (org.assertj.core.util.Arrays.array)4 Mockito.verify (org.mockito.Mockito.verify)4 Collections.singletonList (java.util.Collections.singletonList)3 Objects (java.util.Objects)3 AtomicReferenceArrayAssert (org.assertj.core.api.AtomicReferenceArrayAssert)3 AtomicReferenceArrayAssertBaseTest (org.assertj.core.api.AtomicReferenceArrayAssertBaseTest)3 ConcreteIterableAssert (org.assertj.core.api.ConcreteIterableAssert)3