By
using 'isIn' method, we can create a matcher that matches when the examined
object is found within the specified collection.
Ex
List<String>
names = new ArrayList<>();
names.add("gopi");
names.add("hari");
names.add("krishna");
assertThat("'krishna'
must be part of the list", "krishna", isIn(names));
Find
the below working application.
TestApp.java
package com.sample.tests; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.isIn; import java.util.ArrayList; import java.util.List; import org.junit.Test; public class TestApp { @Test public void testmethod() { List<String> names = new ArrayList<>(); names.add("gopi"); names.add("hari"); names.add("krishna"); assertThat("'krishna' must be part of the list", "krishna", isIn(names)); } }
No comments:
Post a Comment