Search in sources :

Example 6 with ObjectArrays

use of org.assertj.core.internal.ObjectArrays in project assertj-core by joel-costigliola.

the class AtomicReferenceArrayAssert_usingComparatorForType_Test method verify_internal_effects.

@Override
protected void verify_internal_effects() {
    ObjectArrays arrays = getArrays(assertions);
    assertThat(arrays).isNotSameAs(arraysBefore);
    assertThat(arrays.getComparisonStrategy()).isInstanceOf(ComparatorBasedComparisonStrategy.class);
    ComparatorBasedComparisonStrategy strategy = (ComparatorBasedComparisonStrategy) arrays.getComparisonStrategy();
    assertThat(strategy.getComparator()).isInstanceOf(ExtendedByTypesComparator.class);
}
Also used : ComparatorBasedComparisonStrategy(org.assertj.core.internal.ComparatorBasedComparisonStrategy) ObjectArrays(org.assertj.core.internal.ObjectArrays)

Example 7 with ObjectArrays

use of org.assertj.core.internal.ObjectArrays in project assertj-core by joel-costigliola.

the class AbstractObjectArrayAssert method usingElementComparator.

/**
 * Use given custom comparator instead of relying on actual type A <code>equals</code> method to compare group
 * elements for incoming assertion checks.
 * <p>
 * Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default
 * comparison strategy.
 * <p>
 * Examples :
 * <pre><code class='java'> // compares invoices by payee
 * assertThat(invoiceArray).usingComparator(invoicePayeeComparator).isEqualTo(expectedinvoiceArray).
 *
 * // compares invoices by date, doesNotHaveDuplicates and contains both use the given invoice date comparator
 * assertThat(invoiceArray).usingComparator(invoiceDateComparator).doesNotHaveDuplicates().contains(may2010Invoice)
 *
 * // as assertThat(invoiceArray) creates a new assertion, it falls back to standard comparison strategy
 * // based on Invoice's equal method to compare invoiceArray elements to lowestInvoice.
 * assertThat(invoiceArray).contains(lowestInvoice).
 *
 * // standard comparison : the fellowshipOfTheRing includes Gandalf but not Sauron (believe me) ...
 * assertThat(fellowshipOfTheRing).contains(gandalf)
 *                                .doesNotContain(sauron);
 *
 * // ... but if we compare only races, Sauron is in fellowshipOfTheRing because he's a Maia like Gandalf.
 * assertThat(fellowshipOfTheRing).usingElementComparator(raceComparator)
 *                                .contains(sauron);</code></pre>
 *
 * @param elementComparator the comparator to use for incoming assertion checks.
 * @throws NullPointerException if the given comparator is {@code null}.
 * @return {@code this} assertion object.
 */
@Override
@CheckReturnValue
public SELF usingElementComparator(Comparator<? super ELEMENT> elementComparator) {
    this.arrays = new ObjectArrays(new ComparatorBasedComparisonStrategy(elementComparator));
    // to have the same semantics on base assertions like isEqualTo, we need to use an iterable comparator comparing
    // elements with elementComparator parameter
    objects = new Objects(new ObjectArrayElementComparisonStrategy<>(elementComparator));
    return myself;
}
Also used : ObjectArrayElementComparisonStrategy(org.assertj.core.internal.ObjectArrayElementComparisonStrategy) Objects(org.assertj.core.internal.Objects) ComparatorBasedComparisonStrategy(org.assertj.core.internal.ComparatorBasedComparisonStrategy) ObjectArrays(org.assertj.core.internal.ObjectArrays) CheckReturnValue(org.assertj.core.util.CheckReturnValue)

Example 8 with ObjectArrays

use of org.assertj.core.internal.ObjectArrays in project assertj-core by joel-costigliola.

the class ObjectArrayAssert_usingComparatorForType_Test method verify_internal_effects.

@Override
protected void verify_internal_effects() {
    ObjectArrays arrays = getArrays(assertions);
    assertThat(arrays).isNotSameAs(arraysBefore);
    assertThat(arrays.getComparisonStrategy()).isInstanceOf(ComparatorBasedComparisonStrategy.class);
    ComparatorBasedComparisonStrategy strategy = (ComparatorBasedComparisonStrategy) arrays.getComparisonStrategy();
    assertThat(strategy.getComparator()).isInstanceOf(ExtendedByTypesComparator.class);
}
Also used : ComparatorBasedComparisonStrategy(org.assertj.core.internal.ComparatorBasedComparisonStrategy) ObjectArrays(org.assertj.core.internal.ObjectArrays)

Aggregations

ComparatorBasedComparisonStrategy (org.assertj.core.internal.ComparatorBasedComparisonStrategy)8 ObjectArrays (org.assertj.core.internal.ObjectArrays)8 IgnoringFieldsComparator (org.assertj.core.internal.IgnoringFieldsComparator)2 Objects (org.assertj.core.internal.Objects)2 OnFieldsComparator (org.assertj.core.internal.OnFieldsComparator)2 CheckReturnValue (org.assertj.core.util.CheckReturnValue)2 AtomicReferenceArrayElementComparisonStrategy (org.assertj.core.internal.AtomicReferenceArrayElementComparisonStrategy)1 ObjectArrayElementComparisonStrategy (org.assertj.core.internal.ObjectArrayElementComparisonStrategy)1