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<String> names = asList("Dave", "Jeff");
* LinkedHashSet<String> jobs = newLinkedHashSet("Plumber", "Builder");
* Iterable<String> cities = asList("Dover", "Boston", "Paris");
* int[] ranks = { 1, 2, 3 };
*
* Map<String, Object> map = new LinkedHashMap<>();
* 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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations