forked from assertj/assertj
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add values methode in AbstractMapAssert to make assertions on v…
…alues of the map (assertj#3291)
- Loading branch information
1 parent
fba37a3
commit 7da74d8
Showing
2 changed files
with
58 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
assertj-core/src/test/java/org/assertj/core/api/map/MapAssert_values_Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.assertj.core.api.map; | ||
|
||
import org.assertj.core.api.AbstractCollectionAssert; | ||
import org.assertj.core.api.ObjectAssert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
class MapAssert_values_Test { | ||
@Test | ||
void should_return_collection_assertion_on_values_for_map_values() { | ||
Map<String, Integer> map = Map.of("first", 1, "second", 2); | ||
AbstractCollectionAssert<?, Collection<? extends Integer>, Integer, ObjectAssert<Integer>> assertion = | ||
assertThat(map).values(); | ||
assertion.contains(1, 2); | ||
} | ||
|
||
@Test | ||
void should_return_collection_assertion_with_right_generic_type() { | ||
assertThat(Map.of("first", "one")) | ||
.values() | ||
.singleElement() | ||
.returns('o', from(s -> s.charAt(0))); | ||
} | ||
|
||
|
||
@Test | ||
void should_have_an_helpful_error_message_when_size_is_used_on_a_null_map() { | ||
Map<String, String> nullMap = null; | ||
assertThatNullPointerException().isThrownBy(() -> assertThat(nullMap).values().contains("nothing")) | ||
.withMessage("Can not extract values from a null map."); | ||
} | ||
} |