By
using isEmptyOrNullString, you can create a matcher that matches when the
examined string is null, or has zero length.
Ex
String
str1 = "";
String
str2 = null;
assertThat("str1
should be empty", str1, isEmptyOrNullString());
assertThat("str2
should be null", str2, isEmptyOrNullString());
Find
the below working application.
TestApp.java
package com.sample.tests; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.isEmptyOrNullString; import org.junit.Test; public class TestApp { @Test public void testmethod() { String str1 = ""; String str2 = null; assertThat("str1 should be empty", str1, isEmptyOrNullString()); assertThat("str2 should be null", str2, isEmptyOrNullString()); } }
No comments:
Post a Comment