use of org.assertj.core.util.CheckReturnValue 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;
}
use of org.assertj.core.util.CheckReturnValue 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;
}
use of org.assertj.core.util.CheckReturnValue in project assertj-core by joel-costigliola.
the class AbstractIterableAssert method usingComparatorForType.
/**
* Allows to set a specific comparator for the given type of elements or their fields.
* Extends {@link #usingComparatorForElementFieldsWithType} by applying comparator specified for given type
* to elements themselves, not only to their fields.
* <p>
* Usage of this method affects comparators set by next methods:
* <ul>
* <li>{@link #usingFieldByFieldElementComparator}</li>
* <li>{@link #usingElementComparatorOnFields}</li>
* <li>{@link #usingElementComparatorIgnoringFields}</li>
* <li>{@link #usingRecursiveFieldByFieldElementComparator}</li>
* </ul>
* <p>
* Example:
* <pre><code class='java'>
* // assertion will pass
* assertThat(asList("some", new BigDecimal("4.2")))
* .usingComparatorForType(BIG_DECIMAL_COMPARATOR, BigDecimal.class)
* .contains(new BigDecimal("4.20"));
* </code></pre>
*
* @param <T> the type of elements to compare.
* @param comparator the {@link java.util.Comparator} to use
* @param type the {@link java.lang.Class} of the type of the element or element fields the comparator should be used for
* @return {@code this} assertions object
* @since 2.9.0 / 3.9.0
*/
@CheckReturnValue
public <T> SELF usingComparatorForType(Comparator<T> comparator, Class<T> type) {
if (iterables.getComparator() == null) {
usingElementComparator(new ExtendedByTypesComparator(getComparatorsByType()));
}
getComparatorsForElementPropertyOrFieldTypes().put(type, comparator);
getComparatorsByType().put(type, comparator);
return myself;
}
use of org.assertj.core.util.CheckReturnValue 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;
}
use of org.assertj.core.util.CheckReturnValue in project assertj-core by joel-costigliola.
the class AbstractLongAssert method usingComparator.
@Override
@CheckReturnValue
public SELF usingComparator(Comparator<? super Long> customComparator, String customComparatorDescription) {
super.usingComparator(customComparator, customComparatorDescription);
longs = new Longs(new ComparatorBasedComparisonStrategy(customComparator, customComparatorDescription));
return myself;
}
Aggregations