By
using hasValue method, you can create a matcher that is used to check whether
map contains at least one value that is equal to the specified value.
Ex
Map<String,
String> employeeMap = new HashMap<>();
employeeMap.put("I1234",
"Krishna Gurram");
employeeMap.put("I346",
"Chamu M");
employeeMap.put("I546",
"Sri Ram");
assertThat("employeeMap
must contain the key 'I346'", employeeMap, hasValue("Sri Ram"));
Find
the below working application.
package com.sample.tests; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasValue; import java.util.HashMap; import java.util.Map; import org.junit.Test; public class TestApp { @Test public void testmethod() { Map<String, String> employeeMap = new HashMap<>(); employeeMap.put("I1234", "Krishna Gurram"); employeeMap.put("I346", "Chamu M"); employeeMap.put("I546", "Sri Ram"); assertThat("employeeMap must contain the value Sri Ram", employeeMap, hasValue("Sri Ram")); } }
No comments:
Post a Comment