| allOf() | This calculates the logical CONJUNCTION of multiple matchers and the object under consideration should match all of the matcher given. | assertThat("InterviewBit",allOf(startsWith("In"),containsString(“Bit”))) --> All conditions should match for assertThat to pass. |
|---|
| anyOf() | This is used for calculating the logical disjunction of multiple matchers. This means that the object under consideration matches ANY of the specified matchers. | assertThat( "InterviewBit",anyOf(containsString( "Bit" ),containsString( "unit" ))); -->Any of the conditions should match for assertThat to pass. |
|---|
| describedAs() | This adds a description to the matcher. | assertThat("Friday", describedAs("Friday is not Sunday", is(not("Sunday")))); |
|---|
| is() | This decorates another matcher by retaining its behavior. and checks for the equality of the objects. It allows tests to be more EXPRESSIVE and meaningful. | assertThat("InterviewBit",is(equalTo("InterviewBit"))) |
|---|
| anything() | This matcher always returns true. | assertThat("InterviewBit",is(anything("foo bar"))); |
|---|
| equalTo() | This checks for the equality of objects. | assertThat("InterviewBit",equalTo("InterviewBit")); |
|---|
| instanceOf() | This tests whether the value is an instance of any class. | assertThat(instance,instanceOf(InstanceClass.class)); |
|---|
| hasItems() | This creates matcher for iterables which matches when consecutive passes over Iterable yields at least one item equal to corresponding item from list of items. The iterable STOPS as soon as matching item is found. | assertThat(Arrays.asList("Interviewbit", "Junit", "Interview","Questions"), hasItems("Junit", "Questions")) |
|---|
| not() | This creates matcher which wraps existing matcher but inverts logic by which it should match. | assertThat("InterviewBit", is(not(equalTo("Junit")))); |
|---|
| nullValue() | This creates matcher which matches if object that is examined is null. | assertThat(obj, is(nullValue())); |
|---|