By
using 'both' method, you can create a matcher that matches when both the specified
matchers match the examined object.
Ex
String
name = "Hello World";
assertThat(name,
both(startsWith("Hello")).and(containsString("rld")));
TestApp.java
package com.sample.tests; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.both; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.startsWith; import org.junit.Test; public class TestApp { @Test public void testmethod() { String name = "Hello World"; assertThat(name, both(startsWith("Hello")).and(containsString("rld"))); } }
No comments:
Post a Comment