Search in sources :

Example 6 with CheckReturnValue

use of org.assertj.core.util.CheckReturnValue in project assertj-core by joel-costigliola.

the class AbstractMapAssert method flatExtracting.

/**
 * Flatten the values of the given keys from the actual map under test into a new array, this new array becoming the object under test.
 * <p>
 * If a given key is not present in the map under test, a {@code null} value is extracted.
 * <p>
 * If a given key value is not an {@link Iterable} or an array, it is simply extracted but (obviously) not flattened.
 * <p>
 * Example:
 * <pre><code class='java'> List&lt;String&gt; names = asList("Dave", "Jeff");
 * LinkedHashSet&lt;String&gt; jobs = newLinkedHashSet("Plumber", "Builder");
 * Iterable&lt;String&gt; cities = asList("Dover", "Boston", "Paris");
 * int[] ranks = { 1, 2, 3 };
 *
 * Map&lt;String, Object&gt; map = new LinkedHashMap&lt;&gt;();
 * map.put("name", names);
 * map.put("job", jobs);
 * map.put("city", cities);
 * map.put("rank", ranks);
 *
 * assertThat(map).flatExtracting("name","job","city", "rank")
 *                .containsExactly("Dave", "Jeff",
 *                                 "Plumber", "Builder",
 *                                 "Dover", "Boston", "Paris",
 *                                 1, 2, 3);
 *
 * // the order of values in the resulting array is the order of map keys then key values:
 * assertThat(map).flatExtracting("city", "job", "name")
 *                .containsExactly("Dover", "Boston", "Paris",
 *                                 "Plumber", "Builder",
 *                                 "Dave", "Jeff");
 *
 * // contains exactly null twice (one for each unknown keys)
 * assertThat(map).flatExtracting("foo", "name", "bar")
 *                .containsExactly(null, "Dave", "Jeff", null);
 *
 * // if the key value is not an iterable/array, it will be simply extracted but not flattened.
 * map.put("year", 2017));
 * assertThat(map).flatExtracting("name","job","year")
 *                .containsExactly("Dave", "Jeff", "Plumber", "Builder", "Dover", 2017);</code></pre>
 * <p>
 * Note that the order of values in the resulting array is the order of the map keys iteration then key values.
 *
 * @param keys the keys used to get values from the map under test
 * @return a new assertion object whose object under test is the array containing the extracted flattened map values
 */
@CheckReturnValue
public AbstractListAssert<?, List<? extends Object>, Object, ObjectAssert<Object>> flatExtracting(String... keys) {
    Tuple values = byName(keys).extract(actual);
    List<Object> valuesFlattened = flatten(values.toList());
    String extractedPropertiesOrFieldsDescription = extractedDescriptionOf(keys);
    String description = mostRelevantDescription(info.description(), extractedPropertiesOrFieldsDescription);
    return newListAssertInstance(valuesFlattened).as(description);
}
Also used : Tuple(org.assertj.core.groups.Tuple) CheckReturnValue(org.assertj.core.util.CheckReturnValue)

Example 7 with CheckReturnValue

use of org.assertj.core.util.CheckReturnValue in project assertj-core by joel-costigliola.

the class AbstractShortAssert method usingComparator.

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

Example 8 with CheckReturnValue

use of org.assertj.core.util.CheckReturnValue in project assertj-core by joel-costigliola.

the class AbstractFloatAssert method usingComparator.

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

Example 9 with CheckReturnValue

use of org.assertj.core.util.CheckReturnValue in project assertj-core by joel-costigliola.

the class AbstractCharSequenceAssert method usingComparator.

@Override
@CheckReturnValue
public SELF usingComparator(Comparator<? super ACTUAL> customComparator, String customComparatorDescription) {
    super.usingComparator(customComparator, customComparatorDescription);
    this.strings = new Strings(new ComparatorBasedComparisonStrategy(customComparator, customComparatorDescription));
    return myself;
}
Also used : ComparatorBasedComparisonStrategy(org.assertj.core.internal.ComparatorBasedComparisonStrategy) Strings(org.assertj.core.internal.Strings) CheckReturnValue(org.assertj.core.util.CheckReturnValue)

Example 10 with CheckReturnValue

use of org.assertj.core.util.CheckReturnValue in project assertj-core by joel-costigliola.

the class AbstractCharacterAssert method usingComparator.

@Override
@CheckReturnValue
public SELF usingComparator(Comparator<? super Character> customComparator, String customComparatorDescription) {
    super.usingComparator(customComparator, customComparatorDescription);
    this.characters = new Characters(new ComparatorBasedComparisonStrategy(customComparator, customComparatorDescription));
    return myself;
}
Also used : Characters(org.assertj.core.internal.Characters) ComparatorBasedComparisonStrategy(org.assertj.core.internal.ComparatorBasedComparisonStrategy) CheckReturnValue(org.assertj.core.util.CheckReturnValue)

Aggregations

CheckReturnValue (org.assertj.core.util.CheckReturnValue)24 ComparatorBasedComparisonStrategy (org.assertj.core.internal.ComparatorBasedComparisonStrategy)18 ExtendedByTypesComparator (org.assertj.core.internal.ExtendedByTypesComparator)3 Objects (org.assertj.core.internal.Objects)3 Tuple (org.assertj.core.groups.Tuple)2 Comparables (org.assertj.core.internal.Comparables)2 Integers (org.assertj.core.internal.Integers)2 Longs (org.assertj.core.internal.Longs)2 ObjectArrays (org.assertj.core.internal.ObjectArrays)2 AtomicReferenceArrayElementComparisonStrategy (org.assertj.core.internal.AtomicReferenceArrayElementComparisonStrategy)1 BigDecimals (org.assertj.core.internal.BigDecimals)1 BigIntegers (org.assertj.core.internal.BigIntegers)1 Bytes (org.assertj.core.internal.Bytes)1 Characters (org.assertj.core.internal.Characters)1 Dates (org.assertj.core.internal.Dates)1 Doubles (org.assertj.core.internal.Doubles)1 Floats (org.assertj.core.internal.Floats)1 IterableElementComparisonStrategy (org.assertj.core.internal.IterableElementComparisonStrategy)1 Iterables (org.assertj.core.internal.Iterables)1 Lists (org.assertj.core.internal.Lists)1