Saturday 10 March 2018

Hamcrest: emptyArray: match empty array

By using ‘emptyArray’ method, you can create a matcher for arrays that matches when the length of the array is zero.

Ex
String arr[] = {};
assertThat("arr size should be equal to 0", arr, emptyArray());

TestApp.java
package com.sample.tests;

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

import org.junit.Test;

public class TestApp {

 @Test
 public void testmethod() {
  String arr[] = {};
  assertThat("arr size should be equal to 0", arr, emptyArray());
 }
}




Previous                                                 Next                                                 Home

No comments:

Post a Comment