Search in sources :

Example 21 with ComparatorBasedComparisonStrategy

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

the class ShouldNotEndWith_create_Test method should_create_error_message_with_custom_comparison_strategy.

@Test
public void should_create_error_message_with_custom_comparison_strategy() {
    factory = shouldNotEndWith(newArrayList("Yoda", "Luke"), newArrayList("Han", "Leia"), new ComparatorBasedComparisonStrategy(CaseInsensitiveStringComparator.instance));
    String message = factory.create(new TextDescription("Test"), new StandardRepresentation());
    assertThat(message).isEqualTo(String.format("[Test] %n" + "Expecting:%n" + "  <[\"Yoda\", \"Luke\"]>%n" + "not to end with:%n" + "  <[\"Han\", \"Leia\"]>%n" + "when comparing values using CaseInsensitiveStringComparator"));
}
Also used : TextDescription(org.assertj.core.description.TextDescription) StandardRepresentation(org.assertj.core.presentation.StandardRepresentation) ComparatorBasedComparisonStrategy(org.assertj.core.internal.ComparatorBasedComparisonStrategy) Test(org.junit.Test)

Example 22 with ComparatorBasedComparisonStrategy

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

the class ShouldNotBeIn_create_Test method should_create_error_message_with_custom_comparison_strategy.

@Test
public void should_create_error_message_with_custom_comparison_strategy() {
    factory = shouldNotBeIn("Luke", array("Luke", "Leia"), new ComparatorBasedComparisonStrategy(CaseInsensitiveStringComparator.instance));
    String message = factory.create(new TextDescription("Test"), new StandardRepresentation());
    assertThat(message).isEqualTo(String.format("[Test] %n" + "Expecting:%n" + " <\"Luke\">%n" + "not to be in:%n" + " <[\"Luke\", \"Leia\"]>%n" + "when comparing values using CaseInsensitiveStringComparator"));
}
Also used : TextDescription(org.assertj.core.description.TextDescription) StandardRepresentation(org.assertj.core.presentation.StandardRepresentation) ComparatorBasedComparisonStrategy(org.assertj.core.internal.ComparatorBasedComparisonStrategy) Test(org.junit.Test)

Example 23 with ComparatorBasedComparisonStrategy

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

the class AtomicIntegerAssert method usingComparator.

@Override
@CheckReturnValue
public AtomicIntegerAssert usingComparator(Comparator<? super AtomicInteger> customComparator, String customComparatorDescription) {
    super.usingComparator(customComparator, customComparatorDescription);
    integers = new Integers(new ComparatorBasedComparisonStrategy(customComparator, customComparatorDescription));
    return myself;
}
Also used : Integers(org.assertj.core.internal.Integers) ComparatorBasedComparisonStrategy(org.assertj.core.internal.ComparatorBasedComparisonStrategy) CheckReturnValue(org.assertj.core.util.CheckReturnValue)

Example 24 with ComparatorBasedComparisonStrategy

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

the class AtomicReferenceArrayAssert method usingElementComparator.

/**
 * Use given custom comparator instead of relying on actual element type <code>equals</code> method to compare AtomicReferenceArray
 * 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 AtomicReferenceArrayAssert<T> usingElementComparator(Comparator<? super T> elementComparator) {
    this.arrays = new ObjectArrays(new ComparatorBasedComparisonStrategy(elementComparator));
    objects = new Objects(new AtomicReferenceArrayElementComparisonStrategy<>(elementComparator));
    return myself;
}
Also used : AtomicReferenceArrayElementComparisonStrategy(org.assertj.core.internal.AtomicReferenceArrayElementComparisonStrategy) 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 25 with ComparatorBasedComparisonStrategy

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

the class AbstractIterableAssert method usingElementComparator.

/**
 * {@inheritDoc}
 */
@Override
@CheckReturnValue
public SELF usingElementComparator(Comparator<? super ELEMENT> elementComparator) {
    this.iterables = new Iterables(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 IterableElementComparisonStrategy<>(elementComparator));
    return myself;
}
Also used : IterableElementComparisonStrategy(org.assertj.core.internal.IterableElementComparisonStrategy) Objects(org.assertj.core.internal.Objects) ComparatorBasedComparisonStrategy(org.assertj.core.internal.ComparatorBasedComparisonStrategy) Iterables(org.assertj.core.internal.Iterables) CheckReturnValue(org.assertj.core.util.CheckReturnValue)

Aggregations

ComparatorBasedComparisonStrategy (org.assertj.core.internal.ComparatorBasedComparisonStrategy)64 Test (org.junit.Test)26 TextDescription (org.assertj.core.description.TextDescription)24 StandardRepresentation (org.assertj.core.presentation.StandardRepresentation)22 CheckReturnValue (org.assertj.core.util.CheckReturnValue)18 Failures (org.assertj.core.internal.Failures)10 Before (org.junit.Before)10 ObjectArrays (org.assertj.core.internal.ObjectArrays)8 Iterables (org.assertj.core.internal.Iterables)6 AbsValueComparator (org.assertj.core.util.AbsValueComparator)5 IgnoringFieldsComparator (org.assertj.core.internal.IgnoringFieldsComparator)4 Integers (org.assertj.core.internal.Integers)3 Lists (org.assertj.core.internal.Lists)3 Longs (org.assertj.core.internal.Longs)3 Objects (org.assertj.core.internal.Objects)3 OnFieldsComparator (org.assertj.core.internal.OnFieldsComparator)3 Characters (org.assertj.core.internal.Characters)2 Comparables (org.assertj.core.internal.Comparables)2 Doubles (org.assertj.core.internal.Doubles)2 Floats (org.assertj.core.internal.Floats)2