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

Hamcrest: allOf: Match against all the matchers

By using 'allOf' method, you can create a matcher that matches if the specified element is matched against all the matchers.

Ex
String name = "Hello World";
assertThat(name, allOf(startsWith("Hello"), containsString("rld"), endsWith("World")));

Find the below working application.

TestApp.java
package com.sample.tests;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.startsWith;

import org.junit.Test;

public class TestApp {

@Test
public void testmethod() {
String name = "Hello World";

assertThat(name, allOf(startsWith("Hello"), containsString("rld"), endsWith("World")));

}
}



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: allOf: Match against all the matchers

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×