Friday 2 March 2018

Hamcrest: isEmptyString: Match if the string is empty

By using isEmptyString method, you can create a matcher that matches when the examined string has zero length.

Ex
String str = "";
assertThat("str should be empty", str, isEmptyString());

Find the below working application.

TestApp.java
package com.sample.model;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.isEmptyString;

import org.junit.Test;

public class TestApp {

 @Test
 public void testmethod() {
  String str = "";

  assertThat("str should be empty", str, isEmptyString());
 }
}




Previous                                                 Next                                                 Home

No comments:

Post a Comment