Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Hamcrest: iterableWithSize: Check the size of iterable

By using 'iterableWithSize’ method, you can create a matcher that is used to check the size of iterable.

Ex
assertThat(list, Isiterablewithsize. iterableWithSize(3));
                           (or)
assertThat(list, IsIterableWithSize. iterableWithSize(equalTo(3)));

Find the below working application.

TestApp.java
package com.sample.tests;

import static org.hamcrest.MatcherAssert.assertThat;

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

import org.hamcrest.collection.IsIterableWithSize;
import static org.hamcrest.Matchers.equalTo;

import org.junit.Test;

public class TestApp {

@Test
public void testmethod() {
ListInteger> list = Arrays.asList(5, 3, 2);

assertThat(list, IsIterableWithSize.Integer> iterableWithSize(3));

// You can also compare like below.
assertThat(list, IsIterableWithSize.Integer> iterableWithSize(equalTo(3)));
}
}



Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Hamcrest: iterableWithSize: Check the size of iterable

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×