Wednesday 28 March 2018

Hamcrest: emptyCollectionOf: Check the emptiness of collection

By using ‘emptyCollectionOf’ method, you can create a matcher that is used to check whether collection is empty or not.

Ex
List<Integer> tempList = Arrays.asList();
assertThat("empty must be empty", tempList, emptyCollectionOf(Integer.class));

Find the below working application.

TestApp.java
package com.sample.tests;

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

import java.util.Arrays;
import java.util.List;

import org.junit.Test;

public class TestApp {

 @Test
 public void testmethod() {
  List<Integer> tempList = Arrays.asList();
  assertThat("empty must be empty", tempList, emptyCollectionOf(Integer.class));

 }
}



Previous                                                 Next                                                 Home

No comments:

Post a Comment