{"id":49089,"date":"2015-11-15T23:05:31","date_gmt":"2015-11-15T21:05:31","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=49089"},"modified":"2023-12-13T11:10:32","modified_gmt":"2023-12-13T09:10:32","slug":"hamcrest-matchers-tutorial","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html","title":{"rendered":"Hamcrest matchers tutorial"},"content":{"rendered":"<p><em>This article is part of our Academy Course titled <a href=\"http:\/\/www.javacodegeeks.com\/2015\/09\/testing-with-mockito\/\">Testing with Mockito<\/a>.<\/p>\n<p>In this course, you will dive into the magic of Mockito. You will learn about Mocks, Spies and Partial Mocks, and their corresponding Stubbing behaviour. You will also see the process of Verification with Test Doubles and Object Matchers. Finally, Test Driven Development (TDD) with Mockito is discussed in order to see how this library fits in the concept of TDD. Check it out <a href=\"http:\/\/www.javacodegeeks.com\/2015\/09\/testing-with-mockito\/\">here<\/a>!<\/em><br \/>\nIn this tutorial we will look at the Hamcrest Matcher library and how to integrate it with JUnit and Mockito.<\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#hamcrest\">1. What is Hamcrest?<\/a><\/dt>\n<dt><a href=\"#including\">2. Including Hamcrest<\/a><\/dt>\n<dt><a href=\"#meet\">3. Meet the Matchers<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#simple\">3.1. Simple Matchers<\/a><\/dt>\n<dt><a href=\"#simple_comb\">3.2. Simple Matchers Combining Other Matchers<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#conclusion\">4. Conclusion<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><a name=\"hamcrest\"><\/a>1. What is Hamcrest?<\/h2>\n<p>Hamcrest is a framework for creating matcher objects.  These matcher objects are predicates and are used to write rules which can be satisfied under certain conditions.  They are most often used in automated testing, though the can be used in other scenarios such as data validation.  Hamcrest lets us step beyond simple JUnit asserts and enables us to craft very specific, readable verification code.<\/p>\n<p>Hamcrest is designed to make tests very readable. It makes liberal use of static methods to create an assertion grammar which is easy to write and to understand. When used in conjunction with JUnit and Mockito it allows us to write clear, concise tests which satisfy the property of good unit testing which is to \u2018test one thing\u2019.<\/p>\n<p>Suppose we have a String called and we want to test that it is equal to another, expected, string we can use JUnit asserts to test this:<\/p>\n<pre class=\"brush:java\">\nassertEquals(expected, actual);\n<\/pre>\n<p>In Hamcrest we make use of the JUnit <code>assertThat(valueUnderTest, matcher)<\/code> method. This method always forms the basis of the Hamcrest assert; we are asserting that the value under test satisfies the matcher predicate.  To rewrite the above test in hamcrest at it\u2019s most basic level we could write:<\/p>\n<pre class=\"brush:java\">\nassertThat(actual, equalTo(expected));\n<\/pre>\n<p>Note the assertThat convention is to have the actual value under test as the first parameter, this is opposite to the assertEquals convention. This is an improvement on readability, but Hamcrest additionally gives us some nice syntactic sugar in the form of the <code>is()<\/code> matcher.  This matcher does nothing itself, it simply relays the result of its input matcher allowing your assertion code to read just like English.  Let\u2019s rewrite the above using <code>is()<\/code>:<\/p>\n<pre class=\"brush:java\">\nassertThat(actual, is(equalTo(expected)));\n<\/pre>\n<p>Very nice, very readable!<\/p>\n<p>Hamcrest generates detailed output when its matchers fail, specifying the expected values and the actual values, to assist you in figuring out why the test should fail.  Look at the following test case:<\/p>\n<pre class=\"brush:java\">\n@Test\n    public void test_failed() throws Exception {\n        \/\/ Given\n        Integer number = 7;\n\n        \/\/ Then\n        assertThat(number, greaterThan(10));\n    }\n<\/pre>\n<p>Obviously this test will fail, but Hamcrest will give detailed information about the failure:<\/p>\n<pre class=\"brush:shell\">\njava.lang.AssertionError: \nExpected: a value greater than &lt;10&gt;\n     but: &lt;7&gt; was less than &lt;10&gt;\n<\/pre>\n<p>Throughout this tutorial we will stick to the convention of having just one assertion as part of our unit tests. This may seem repetitive, particularly where the setup part of the test is the same across a number of tests, however this is good practice in Unit Testing. It allows us to create tests which are targeted &#8211; tests will fail only if their single assertion fails, every other assertion will continue to execute. It allows us to create tests which are readable &#8211; we can see at a glance the purpose of the test.  It allows us to create test which document the code &#8211; we can use test names which convey the granular purpose of the test, and therefore the behaviour of the code under test (think <code>customer_should_have_balance_updated_by_input_order_amount()<\/code> rather than <code>verifyOrderMethod()<\/code>). It allows us to create tests which are not brittle &#8211; if a test does too much it may break if unrelated functionality is changed, forcing us to rewrite the test just to get it working again without changing the actual code under test.<\/p>\n<p>If we adopt the \u2018test one thing\u2019 habit we will be writing much better unit tests into the future!<\/p>\n<h2><a name=\"including\"><\/a>2. Including Hamcrest<\/h2>\n<p>If you are using Maven you can add Hamcrest to your project with the following dependency to your pom.xml<\/p>\n<pre class=\"brush:xml\">\n&lt;dependency&gt;\n  \t&lt;groupId&gt;org.hamcrest&lt;\/groupId&gt;\n  \t&lt;artifactId&gt;hamcrest-all&lt;\/artifactId&gt;\n  \t&lt;version&gt;1.3&lt;\/version&gt;\n  &lt;\/dependency&gt;\n<\/pre>\n<p>If you are using Gradle add the following<\/p>\n<pre class=\"brush:groovy\">\ndependencies {\n    testCompile \"org.hamcrest:hamcrest-all:1.3\"\n  }\n<\/pre>\n<p>To add hamcrest directly to the classpath of your project you can download hamcrest-all-1.3.jar from https:\/\/code.google.com\/p\/hamcrest\/ to a location on your hard drive.<\/p>\n<p>Right click on your eclipse project and select \u2018Properties\u2019 and then select \u2018Java Build Path\u2019 in the left pane and \u2018Libraries\u2019 on the right.<\/p>\n<p>On the \u2018Libraries\u2019 tab click the \u2018Add External Jars\u2019 button and navigate to the hamcrest-all jar you previously downloaded.  Select the jar and it is now added to your project and available to use.<\/p>\n<p>Note that JUnit gets bundled with a stripped down version of Hamcrest (Hamcrest Core) so your compiler will pick up that version if JUnit appears before Hamcrest on the classpath. To counteract this please ensure Hamcrest appears before JUnit on the classpath.  You can achieve this in Maven by listing the hamcrest-all dependency before all other dependencies.<\/p>\n<p>As with the Mockito static methods we can add the Hamcrest library to Eclipse content assist by launching Window -> Preferences and go to Java\/Editor\/Content Assist\/Favorites in the left nav.  After that add the following as \u201cNew Type\u2026&#8221; as per Figure 1<\/p>\n<ul>\n<li>org.hamcrest.Matchers<\/li>\n<\/ul>\n<p>launch Window -> Preferences and go to Java\/Editor\/Content Assist\/Favorites in the left nav.  After that add the following as \u201cNew Type\u2026&#8221; as per Figure 1<\/p>\n<p><figure id=\"attachment_49092\" aria-describedby=\"caption-attachment-49092\" style=\"width: 624px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/figure_1.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/figure_1.png\" alt=\"Figure 1 - Content Assist Favorites\" width=\"624\" height=\"577\" class=\"size-full wp-image-49092\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/figure_1.png 624w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/figure_1-300x277.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/a><figcaption id=\"caption-attachment-49092\" class=\"wp-caption-text\">Figure 1 &#8211; Content Assist Favorites<\/figcaption><\/figure><\/p>\n<h2><a name=\"meet\"><\/a>3. Meet the Matchers<\/h2>\n<p>Hamcrest provides a library of static factory methods for creating Matchers in the class org.hamcrest.Matchers so you can bring in all the matchers with a static import<\/p>\n<pre class=\"brush:java\">\nimport static org.hamcrest.Matchers.*\n<\/pre>\n<p>However you run the risk of a naming clash if you do this because both Hamcrest and Mockito provide a static <code>any()<\/code> method so it is recommended to import each static method you use individually.<br \/>\nWe will now look at all of the Matchers available to us in the Hamcrest Matchers library.  They will be broken into two broad categories; Matchers which work to test values (Simple), and Matchers which work to combine other Matchers (Aggregate).<\/p>\n<h3><a name=\"simple\"><\/a>3.1. Simple Matchers<\/h3>\n<p>The following matchers primarily work to test input values.<\/p>\n<h4><a name=\"any\"><\/a>3.1.1. any()<\/h4>\n<p>Matches any variable of the given type.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_any() throws Exception {\n\t\t\/\/ Given\n\t\tString myString = \"hello\";\n\t\t\n\t\t\/\/ Then\n\t\tassertThat(myString, is(any(String.class)));\t\t\n\t}\n<\/pre>\n<h4><a name=\"anything\"><\/a>3.1.2. anything()<\/h4>\n<p>Matches anything.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_anything() throws Exception {\n\t\t\/\/ Given\n\t\tString myString = \"hello\";\n\t\tInteger four = 4;\n\t\t\n\t\t\/\/ Then\n\t\tassertThat(myString, is(anything()));\n\t\tassertThat(four, is(anything()));\n\t}\n<\/pre>\n<h4><a name=\"arrayContaining\"><\/a>3.1.3. arrayContaining()<\/h4>\n<p>Various matchers for Arrays, length of the array must match the number of matchers, and their order is important.<\/p>\n<p>Does the array contain all given items in the order in which they are input to the matcher?<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_arrayContaining_items() throws Exception {\n\t\t\/\/ Given\n\t\tString[] strings = {\"why\", \"hello\", \"there\"};\n\t\t\n\t\t\/\/ Then\n\t\tassertThat(strings, is(arrayContaining(\"why\", \"hello\", \"there\")));\n\t}\n<\/pre>\n<p>Does the array contain items which match the input list of matchers, in order?<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_arrayContaining_list_of_matchers() throws Exception {\n\t\t\/\/ Given\n\t\tString[] strings = {\"why\", \"hello\", \"there\"};\n\t\t\n\t\t\/\/ Then\n\t\tjava.util.List&lt;org.hamcrest.Matcher&lt;? super String&gt;&gt; itemMatchers = new ArrayList&lt;&gt;();\n\t\titemMatchers.add(equalTo(\"why\"));\n\t\titemMatchers.add(equalTo(\"hello\"));\n\t\titemMatchers.add(endsWith(\"here\"));\n\t\tassertThat(strings, is(arrayContaining(itemMatchers)));\n\t}\n<\/pre>\n<p>Does the array contain items which match the input vararg matchers, in order?<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_arrayContaining_matchers() throws Exception {\n\t\t\/\/ Given\n\t\tString[] strings = {\"why\", \"hello\", \"there\"};\n\t\t\n\t\t\/\/ Then\n\t\tassertThat(strings, is(arrayContaining(startsWith(\"wh\"), equalTo(\"hello\"), endsWith(\"here\"))));\n\t}\n<\/pre>\n<h4><a name=\"arrayContainingInAnyOrder\"><\/a>3.1.4. arrayContainingInAnyOrder()<\/h4>\n<p>Various matchers for Arrays, length of the array must match the number of matchers, but their order is not important.<\/p>\n<p>Does the array contain all the given items?<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_arrayContainingInAnyOrder_items() throws Exception {\n\t\t\/\/ Given\n\t\tString[] strings = { \"why\", \"hello\", \"there\" };\n\n\t\t\/\/ Then\n\t\tassertThat(strings, is(arrayContainingInAnyOrder(\"hello\", \"there\", \"why\")));\n\t}\n<\/pre>\n<p>Does the array contain items which match the input collection of Matchers?<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_arrayContainingInAnyOrder_collection_of_matchers() throws Exception {\n\t\t\/\/ Given\n\t\tString[] strings = { \"why\", \"hello\", \"there\" };\n\n\t\t\/\/ Then\n\t\tSet&lt;org.hamcrest.Matcher&lt;? super String&gt;&gt; itemMatchers = new HashSet&lt;&gt;();\n\t\titemMatchers.add(equalTo(\"hello\"));\n\t\titemMatchers.add(equalTo(\"why\"));\n\t\titemMatchers.add(endsWith(\"here\"));\n\t\tassertThat(strings, is(arrayContainingInAnyOrder(itemMatchers)));\n\t}\n<\/pre>\n<p>Does the array contain items which match the input vararg matchers?<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_arrayContainingInAnyOrder_matchers() throws Exception {\n\t\t\/\/ Given\n\t\tString[] strings = { \"why\", \"hello\", \"there\" };\n\n\t\t\/\/ Then\n\t\tassertThat(strings, is(arrayContainingInAnyOrder(endsWith(\"lo\"), startsWith(\"the\"), equalTo(\"why\"))));\n\t}\n<\/pre>\n<h4><a name=\"arrayWithSize\"><\/a>3.1.5. arrayWithSize()<\/h4>\n<p>Various matchers to check if an array is of a certain length.<\/p>\n<p>Does the input array have exactly the specified length?<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_arrayWithSize_exact() throws Exception {\n\t\t\/\/ Given\n\t\tString[] strings = { \"why\", \"hello\", \"there\" };\n\n\t\t\/\/ Then\n\t\tassertThat(strings, is(arrayWithSize(3)));\n\t}\n<\/pre>\n<p>Does the input array have a length which matches the specified matcher?<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_arrayWithSize_matcher() throws Exception {\n\t\t\/\/ Given\n\t\tString[] strings = { \"why\", \"hello\", \"there\" };\n\n\t\t\/\/ Then\n\t\tassertThat(strings, is(arrayWithSize(greaterThan(2))));\n\t}\n<\/pre>\n<h4><a name=\"closeTo\"><\/a>3.1.6. closeTo()<\/h4>\n<p>Matcher which can be used with either Double or BigDecimal to check if a value is within a specified error margin of an expected value.<\/p>\n<p>Double<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_closeTo_double() throws Exception {\n\t\t\/\/ Given\n\t\tDouble testValue = 6.3;\n\n\t\t\/\/ Then\n\t\tassertThat(testValue, is(closeTo(6, 0.5)));\n\t}\n<\/pre>\n<p>BigDecimal<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_closeTo_bigDecimal() throws Exception {\n\t\t\/\/ Given\n\t\tBigDecimal testValue = new BigDecimal(324.0);\n\n\t\t\/\/ Then\n\t\tassertThat(testValue, is(closeTo(new BigDecimal(350), new BigDecimal(50))));\n\t}\n\n<\/pre>\n<h4><a name=\"comparesEqualTo\"><\/a>3.1.7. comparesEqualTo()<\/h4>\n<p>Creates a Comparable matcher which attempts to match the input matcher value using the <code>compareTo()<\/code> method of the input value.  The matcher will match if the <code>compareTo()<\/code> method returns 0 for the input matcher value, otherwise it would not match.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_comparesEqualTo() throws Exception {\n\t\t\/\/ Given\n\t\tString testValue = \"value\";\n\n\t\t\/\/ Then\n\t\tassertThat(testValue, comparesEqualTo(\"value\"));\n\t}\n<\/pre>\n<h4><a name=\"contains\"><\/a>3.1.8. contains()<\/h4>\n<p>Various matchers which can be used to check if an input Iterable contains values. The order of the values is important and the number of items in the Iterable must match the number of values being tested.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Does the input list contain all of the values, in order?<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_contains_items() throws Exception {\n\t\t\/\/ Given\n\t\tList&lt;String&gt; strings = Arrays.asList(\"why\", \"hello\", \"there\");\n\n\t\t\/\/ Then\n\t\tassertThat(strings, contains(\"why\", \"hello\", \"there\"));\n\t}\n<\/pre>\n<p>Does the input list contain items which match all of the matchers in the input matchers list, in order?<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_contains_list_of_matchers() throws Exception {\n\t\t\/\/ Given\n\t\tList&lt;String&gt; strings = Arrays.asList(\"why\", \"hello\", \"there\");\n\n\t\t\/\/ Then\n\t\tList&lt;org.hamcrest.Matcher&lt;? super String&gt;&gt; matchers = new ArrayList&lt;&gt;();\n\t\tmatchers.add(startsWith(\"wh\"));\n\t\tmatchers.add(endsWith(\"lo\"));\n\t\tmatchers.add(equalTo(\"there\"));\n\t\tassertThat(strings, contains(matchers));\n\t}\n<\/pre>\n<p>Does the input list contain only one item which matches the input matcher?<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_contains_single_matcher() throws Exception {\n\t\t\/\/ Given\n\t\tList&lt;String&gt; strings = Arrays.asList(\"hello\");\n\n\t\t\/\/ Then\n\t\tassertThat(strings, contains(startsWith(\"he\")));\n\t}\n<\/pre>\n<p>Does the input list contain items which match all of the matchers in the input vararg matchers, in order?<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_contains_matchers() throws Exception {\n\t\t\/\/ Given\n\t\tList&lt;String&gt; strings = Arrays.asList(\"why\", \"hello\", \"there\");\n\n\t\t\/\/ Then\n\t\tassertThat(strings, contains(startsWith(\"why\"), endsWith(\"llo\"), equalTo(\"there\")));\n\t}\n<\/pre>\n<h4><a name=\"containsInAnyOrder\"><\/a>3.1.9. containsInAnyOrder()<\/h4>\n<p>Various matchers which can be used to check if an input Iterable contains values. The order of the values is not important but the number of items in the Iterable must match the number of values being tested.<\/p>\n<p>Does the input list contain all of the values, in any order?<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_containsInAnyOrder_items() throws Exception {\n\t\t\/\/ Given\n\t\tList&lt;String&gt; strings = Arrays.asList(\"why\", \"hello\", \"there\");\n\n\t\t\/\/ Then\n\t\tassertThat(strings, containsInAnyOrder(\"hello\", \"there\", \"why\"));\n\t}\n<\/pre>\n<p>Does the input list contain items which match all of the matchers in the input matchers list, in any order?<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_containsInAnyOrder_list_of_matchers() throws Exception {\n\t\t\/\/ Given\n\t\tList&lt;String&gt; strings = Arrays.asList(\"why\", \"hello\", \"there\");\n\n\t\t\/\/ Then\n\t\tList&lt;org.hamcrest.Matcher&lt;? super String&gt;&gt; matchers = new ArrayList&lt;&gt;();\n\t\tmatchers.add(equalTo(\"there\"));\n\t\tmatchers.add(startsWith(\"wh\"));\n\t\tmatchers.add(endsWith(\"lo\"));\t\t\n\t\tassertThat(strings, containsInAnyOrder(matchers));\n\t}\n<\/pre>\n<p>Does the input list contain items which match all of the matchers in the input vararg matchers, in any order?<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_containsInAnyOrder_matchers() throws Exception {\n\t\t\/\/ Given\n\t\tList&lt;String&gt; strings = Arrays.asList(\"why\", \"hello\", \"there\");\n\n\t\t\/\/ Then\n\t\tassertThat(strings, containsInAnyOrder(endsWith(\"llo\"), equalTo(\"there\"), startsWith(\"why\")));\n\t}\n<\/pre>\n<h4><a name=\"containsString\"><\/a>3.1.10. containsString()<\/h4>\n<p>Matcher which matches if the String under test contains the given substring.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_containsString() throws Exception {\n\t\t\/\/ Given\n\t\tString testValue = \"value\";\n\n\t\t\/\/ Then\n\t\tassertThat(testValue, containsString(\"alu\"));\n\t}\n<\/pre>\n<h4><a name=\"empty\"><\/a>3.1.11. empty()<\/h4>\n<p>Matcher which matches if an input Collections <code>isEmpty()<\/code> method returns true.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_empty() throws Exception {\n\t\t\/\/ Given\n\t\tSet&lt;String&gt; testCollection = new HashSet&lt;&gt;();\n\n\t\t\/\/ Then\n\t\tassertThat(testCollection, is(empty()));\n\t}\n<\/pre>\n<h4><a name=\"emptyArray\"><\/a>3.1.12. emptyArray()<\/h4>\n<p>Matcher which matches if the input array has a length of 0.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_emptyArray() throws Exception {\n\t\t\/\/ Given\n\t\tString[] testArray = new String[0];\n\n\t\t\/\/ Then\n\t\tassertThat(testArray, is(emptyArray()));\n\t}\n\n<\/pre>\n<h4><a name=\"emptyCollectionOf\"><\/a>3.1.13. emptyCollectionOf()<\/h4>\n<p>Typesafe matcher which matches if the input collection is of the given type and is empty.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_emptyCollectionOf() throws Exception {\n\t\t\/\/ Given\n\t\tSet&lt;String&gt; testCollection = new HashSet&lt;&gt;();\n\n\t\t\/\/ Then\n\t\tassertThat(testCollection, is(emptyCollectionOf(String.class)));\n\t}\n<\/pre>\n<h4><a name=\"emptyIterable\"><\/a>3.1.14. emptyIterable()<\/h4>\n<p>Matcher which matches if the input Iterable has no values.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_emptyIterable() throws Exception {\n\t\t\/\/ Given\n\t\tSet&lt;String&gt; testCollection = new HashSet&lt;&gt;();\n\n\t\t\/\/ Then\n\t\tassertThat(testCollection, is(emptyIterable()));\n\t}\n<\/pre>\n<h4><a name=\"emptyIterableOf\"><\/a>3.1.15. emptyIterableOf()<\/h4>\n<p>Typesafe Matcher which matches if the input Iterable has no values and is of the given type.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_emptyIterableOf() throws Exception {\n\t\t\/\/ Given\n\t\tSet&lt;String&gt; testCollection = new HashSet&lt;&gt;();\n\n\t\t\/\/ Then\n\t\tassertThat(testCollection, is(emptyIterableOf(String.class)));\n\t}\n<\/pre>\n<h4><a name=\"endsWith\"><\/a>3.1.16. endsWith()<\/h4>\n<p>Matcher which matches if the input String ends with the given substring.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_endsWith() throws Exception {\n\t\t\/\/ Given\n\t\tString testValue = \"value\";\n\n\t\t\/\/ Then\n\t\tassertThat(testValue, endsWith(\"lue\"));\n\t}\n<\/pre>\n<h4><a name=\"equalTo\"><\/a>3.1.17. equalTo()<\/h4>\n<p>Matcher which matches if the input value is logically equal to the given test value. Can also be used on Arrays in which case it will check the length of the Array and ensure that all the values in the input test array are logically equal to the values of the specified array.<\/p>\n<p>Single value.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_equalTo_value() throws Exception {\n\t\t\/\/ Given\n\t\tString testValue = \"value\";\n\n\t\t\/\/ Then\n\t\tassertThat(testValue, equalTo(\"value\"));\n\t}\n<\/pre>\n<p>Array.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_equalTo_array() throws Exception {\n\t\t\/\/ Given\n\t\tString[] testValues = { \"why\", \"hello\", \"there\" };\n\n\t\t\/\/ Then\n\t\tString[] specifiedValues = { \"why\", \"hello\", \"there\" };\n\t\tassertThat(testValues, equalTo(specifiedValues));\n\t}\n<\/pre>\n<h4><a name=\"equalToIgnoringCase\"><\/a>3.1.18. equalToIgnoringCase()<\/h4>\n<p>Matcher which matches if the input String value is equal to the specified String while ignoring case.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_equalToIgnoringCase() throws Exception {\n\t\t\/\/ Given\n\t\tString testValue = \"value\";\n\n\t\t\/\/ Then\n\t\tassertThat(testValue, equalToIgnoringCase(\"VaLuE\"));\n\t}\n<\/pre>\n<h4><a name=\"equalToIgnoringWhiteSpace\"><\/a>3.1.19. equalToIgnoringWhiteSpace()<\/h4>\n<p>Matcher which matches if the input String value is equal to the specified String while ignoring superfluous white space. All leading and trailing whitespace are ignored, and all remaining whitespace is collapsed to a single space.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_equalToIgnoringWhiteSpace() throws Exception {\n\t\t\/\/ Given\n\t\tString testValue = \"this    is   my    value    \";\n\n\t\t\/\/ Then\n\t\tassertThat(testValue, equalToIgnoringWhiteSpace(\"this is my value\"));\n\t}\n<\/pre>\n<h4><a name=\"eventFrom\"><\/a>3.1.20. eventFrom()<\/h4>\n<p>Matcher which matches if an input <code>EventObject<\/code> is from the given Source. Can also accept an <code>EventObeject<\/code> of a specified subtype.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_eventFrom() throws Exception {\n\t\t\/\/ Given\n\t\tObject source = new Object();\n\t\tEventObject testEvent = new EventObject(source);\n\n\t\t\/\/ Then\n\t\tassertThat(testEvent, is(eventFrom(source)));\n\t}\n<\/pre>\n<p>With subtype specified.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_eventFrom_type() throws Exception {\n\t\t\/\/ Given\n\t\tObject source = new Object();\n\t\tEventObject testEvent = new MenuEvent(source);\n\n\t\t\/\/ Then\n\t\tassertThat(testEvent, is(eventFrom(MenuEvent.class, source)));\n\t}\n<\/pre>\n<h4><a name=\"greaterThan\"><\/a>3.1.21. greaterThan()<\/h4>\n<p>Matcher which matches if an input test value is greater than a specified value.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_greaterThan() throws Exception {\n\t\t\/\/ Given\n\t\tInteger testValue = 5;\n\n\t\t\/\/ Then\n\t\tassertThat(testValue, is(greaterThan(3)));\n\t}\n<\/pre>\n<h4><a name=\"greaterThanOrEqual\"><\/a>3.1.22. greaterThanOrEqual()<\/h4>\n<p>Matcher which matches if an input test value is greater than or equal to a specified value.<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_greaterThanOrEqualTo() throws Exception {\n\t\t\/\/ Given\n\t\tInteger testValue = 3;\n\n\t\t\/\/ Then\n\t\tassertThat(testValue, is(greaterThanOrEqualTo(3)));\n\t}\n<\/pre>\n<h4><a name=\"hasEntry\"><\/a>3.1.23. hasEntry()<\/h4>\n<p>Matchers which match if a given map contains an entry which matches the specified key and value, or matchers.<\/p>\n<p>Actual Values<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasEntry() throws Exception {\n\t\t\/\/ Given\n\t\tInteger testKey = 1;\n\t\tString testValue = \"one\";\n\t\t\n\t\tMap&lt;Integer, String&gt; testMap = new HashMap&lt;&gt;();\n\t\ttestMap.put(testKey, testValue);\n\n\t\t\/\/ Then\n\t\tassertThat(testMap, hasEntry(1, \"one\"));\n\t}\n<\/pre>\n<p>Matchers<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasEntry_matchers() throws Exception {\n\t\t\/\/ Given\n\t\tInteger testKey = 2;\n\t\tString testValue = \"two\";\n\t\t\n\t\tMap&lt;Integer, String&gt; testMap = new HashMap&lt;&gt;();\n\t\ttestMap.put(testKey, testValue);\n\n\t\t\/\/ Then\n\t\tassertThat(testMap, hasEntry(greaterThan(1), endsWith(\"o\")));\n\t}\n<\/pre>\n<h4><a name=\"hasItem\"><\/a>3.1.24. hasItem()<\/h4>\n<p>Matchers which match if the input Iterable has at least one item that matches the specified value or matcher.<\/p>\n<p>Actual Value<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasItem() throws Exception {\n\t\t\/\/ Given\n\t\tList&lt;Integer&gt; testList = Arrays.asList(1,2,7,5,4,8);\n\n\t\t\/\/ Then\n\t\tassertThat(testList, hasItem(4));\n\t}\n<\/pre>\n<p>Matcher<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasItem_matcher() throws Exception {\n\t\t\/\/ Given\n\t\tList&lt;Integer&gt; testList = Arrays.asList(1,2,7,5,4,8);\n\n\t\t\/\/ Then\n\t\tassertThat(testList, hasItem(is(greaterThan(6))));\n\t}\n<\/pre>\n<h4><a name=\"hasItemInArray\"><\/a>3.1.25. hasItemInArray()<\/h4>\n<p>Matchers which match if the input Array has at least one item that matches the specified value or matcher.<\/p>\n<p>Actual Value<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasItemInArray() throws Exception {\n\t\t\/\/ Given\n\t\tInteger[] test = {1,2,7,5,4,8};\n\n\t\t\/\/ Then\n\t\tassertThat(test, hasItemInArray(4));\n\t}\n<\/pre>\n<p>Matcher<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasItemInArray_matcher() throws Exception {\n\t\t\/\/ Given\n\t\tInteger[] test = {1,2,7,5,4,8};\n\n\t\t\/\/ Then\n\t\tassertThat(test, hasItemInArray(is(greaterThan(6))));\n\t}\n<\/pre>\n<h4><a name=\"hasItems\"><\/a>3.1.26. hasItems()<\/h4>\n<p>Matchers which match if the input Iterable has all of the specified values or matchers, in any order.<\/p>\n<p>Actual Values<\/p>\n<pre class=\"brush:java\">\npublic void test_hasItems() throws Exception {\n\t\t\/\/ Given\n\t\tList&lt;Integer&gt; testList = Arrays.asList(1,2,7,5,4,8);\n\n\t\t\/\/ Then\n\t\tassertThat(testList, hasItems(4, 2, 5));\n\t}\n<\/pre>\n<p>Matchers<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasItems_matcher() throws Exception {\n\t\t\/\/ Given\n\t\tList&lt;Integer&gt; testList = Arrays.asList(1,2,7,5,4,8);\n\n\t\t\/\/ Then\n\t\tassertThat(testList, hasItems(greaterThan(6), lessThan(2)));\n\t}\n<\/pre>\n<h4><a name=\"hasKey\"><\/a>3.1.27. hasKey()<\/h4>\n<p>Matchers which match if the input Map has at least one key which matches the specified value or matcher.<\/p>\n<p>Actual Value<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasKey() throws Exception {\n\t\t\/\/ Given\n\t\tMap&lt;String, String&gt; testMap = new HashMap&lt;&gt;();\n\t\ttestMap.put(\"hello\", \"there\");\n\t\ttestMap.put(\"how\", \"are you?\");\n\n\t\t\/\/ Then\n\t\tassertThat(testMap, hasKey(\"hello\"));\n\t}\n<\/pre>\n<p>Matcher<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasKey_matcher() throws Exception {\n\t\t\/\/ Given\n\t\tMap&lt;String, String&gt; testMap = new HashMap&lt;&gt;();\n\t\ttestMap.put(\"hello\", \"there\");\n\t\ttestMap.put(\"how\", \"are you?\");\n\n\t\t\/\/ Then\n\t\tassertThat(testMap, hasKey(startsWith(\"h\")));\n\t}\n<\/pre>\n<h4><a name=\"hasProperty\"><\/a>3.1.28. hasProperty()<\/h4>\n<p>Matcher which matches if the input Object satisfies the Bean Convention and has a property with the specified name and optionally the value of the property matches the specified matcher.<\/p>\n<p>Property Name<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasProperty() throws Exception {\n\t\t\/\/ Given\n\t\tJTextField testBean = new JTextField();\n\t\ttestBean.setText(\"Hello, World!\");\n\n\t\t\/\/ Then\n\t\tassertThat(testBean, hasProperty(\"text\"));\n\t}\n<\/pre>\n<p>Property Name and Value Matcher<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasProperty_value() throws Exception {\n\t\t\/\/ Given\n\t\tJTextField testBean = new JTextField();\n\t\ttestBean.setText(\"Hello, World!\");\n\n\t\t\/\/ Then\n\t\tassertThat(testBean, hasProperty(\"text\", startsWith(\"H\")));\n\t}\n<\/pre>\n<h4><a name=\"hasSize\"><\/a>3.1.29. hasSize()<\/h4>\n<p>Matchers which match if the input Collection has the specified size, or it\u2019s size matches the specified matcher.<br \/>\nActual Value<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasSize() throws Exception {\n\t\t\/\/ Given\n\t\tList&lt;Integer&gt; testList = Arrays.asList(1,2,3,4,5);\n\n\t\t\/\/ Then\n\t\tassertThat(testList, hasSize(5));\n\t}\n<\/pre>\n<p>Matcher<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasSize_matcher() throws Exception {\n\t\t\/\/ Given\n\t\tList&lt;Integer&gt; testList = Arrays.asList(1,2,3,4,5);\n\n\t\t\/\/ Then\n\t\tassertThat(testList, hasSize(lessThan(10)));\n\t}\n<\/pre>\n<h4><a name=\"hasToString\"><\/a>3.1.30. hasToString()<\/h4>\n<p>Matchers which match if the input Object\u2019s toString() method matches either the specified String or the input matcher.<\/p>\n<p>Atual Value<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasToString() throws Exception {\n\t\t\/\/ Given\n\t\tInteger testValue = 4;\n\n\t\t\/\/ Then\n\t\tassertThat(testValue, hasToString(\"4\"));\n\t}\n<\/pre>\n<p>Matcher<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasToString_matcher() throws Exception {\n\t\t\/\/ Given\n\t\tDouble testValue = 3.14;\n\n\t\t\/\/ Then\n\t\tassertThat(testValue, hasToString(containsString(\".\")));\n\t}\n<\/pre>\n<h4><a name=\"hasValue\"><\/a>3.1.31. hasValue()<\/h4>\n<p>Matchers which match if the input Map has at least one value that matches the specified value or matcher.<\/p>\n<p>Actual Value<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasValue() throws Exception {\n\t\t\/\/ Given\n\t\tMap&lt;String, String&gt; testMap = new HashMap&lt;&gt;();\n\t\ttestMap.put(\"hello\", \"there\");\n\t\ttestMap.put(\"how\", \"are you?\");\n\n\t\t\/\/ Then\n\t\tassertThat(testMap, hasValue(\"there\"));\n\t}\n<\/pre>\n<p>Matcher<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasValue_matcher() throws Exception {\n\t\t\/\/ Given\n\t\tMap&lt;String, String&gt; testMap = new HashMap&lt;&gt;();\n\t\ttestMap.put(\"hello\", \"there\");\n\t\ttestMap.put(\"how\", \"are you?\");\n\n\t\t\/\/ Then\n\t\tassertThat(testMap, hasValue(containsString(\"?\")));\n\t}\n<\/pre>\n<h4><a name=\"hasXPath\"><\/a>3.1.32. hasXPath()<\/h4>\n<p>Matchers which match if the input XML DOM Node satisfies the input XPath expression.<\/p>\n<p>Does the Node contain a Node which matches the input XPath expression?<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasXPath() throws Exception {\n\t\t\/\/ Given\n\t\tDocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();\n\t\tNode testNode = docBuilder.parse(\n\t\t        new InputSource(new StringReader(\"&lt;xml&gt;&lt;top&gt;&lt;middle&gt;&lt;bottom&gt;value&lt;\/bottom&gt;&lt;\/middle&gt;&lt;\/top&gt;&lt;\/xml&gt;\")))\n\t\t        .getDocumentElement();\n\n\t\t\/\/ Then\n\t\tassertThat(testNode, hasXPath(\"\/xml\/top\/middle\/bottom\"));\n\t}\n<\/pre>\n<p>Does the Node contain a Node which matches the input XPath expression and does that Node have a value which matches the specified matcher?<\/p>\n<pre class=\"brush:java\">\n@Test\n\tpublic void test_hasXPath_matcher() throws Exception {\n\t\t\/\/ Given\n\t\tDocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();\n\t\tNode testNode = docBuilder.parse(\n\t\t        new InputSource(new StringReader(\"&lt;xml&gt;&lt;top&gt;&lt;middle&gt;&lt;bottom&gt;value&lt;\/bottom&gt;&lt;\/middle&gt;&lt;\/top&gt;&lt;\/xml&gt;\")))\n\t\t        .getDocumentElement();\n\n\t\t\/\/ Then\n\t\tassertThat(testNode, hasXPath(\"\/xml\/top\/middle\/bottom\", startsWith(\"val\")));\n\t}\n<\/pre>\n<p>Does the Node contain a Node in the specified namespace which matches the input XPath expression?<\/p>\n<pre class=\"brush:java\">\n@Test\npublic void test_hasXPath_namespace() throws Exception {\n   \/\/ Given\n   DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();\n   docFactory.setNamespaceAware(true);\n   DocumentBuilder docBuilder = docFactory.newDocumentBuilder();\n   Node testNode = docBuilder.parse(\n           new InputSource(new StringReader(\"&lt;xml xmlns:prefix='http:\/\/namespace-uri'&gt;&lt;top&gt;&lt;middle&gt;&lt;prefix:bottom&gt;value&lt;\/prefix:bottom&gt;&lt;\/middle&gt;&lt;\/top&gt;&lt;\/xml&gt;\")))\n           .getDocumentElement();\n\n   NamespaceContext namespace = new NamespaceContext() {\n       public String getNamespaceURI(String prefix) {\n           return \"http:\/\/namespace-uri\";\n       }\n\n       public String getPrefix(String namespaceURI) {\n           return null;\n       }\n\n       public Iterator&lt;String&gt; getPrefixes(String namespaceURI) {\n           return null;\n       }\n   };\n\n   \/\/ Then\n   assertThat(testNode, hasXPath(\"\/\/prefix:bottom\", namespace));\n}\n<\/pre>\n<p>Does the Node contain a Node in the specified namespace which matches the input XPath expression and does that Node have a value which matches the specified matcher?<\/p>\n<pre class=\"brush:java\">\n@Test\npublic void test_hasXPath_namespace_matcher() throws Exception {\n  \/\/ Given\n  DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();\n  docFactory.setNamespaceAware(true);\n  DocumentBuilder docBuilder = docFactory.newDocumentBuilder();\n  Node testNode = docBuilder.parse(\n        new InputSource(new StringReader(\"&lt;xml xmlns:prefix='http:\/\/namespace-uri'&gt;&lt;top&gt;&lt;middle&gt;&lt;prefix:bottom&gt;value&lt;\/prefix:bottom&gt;&lt;\/middle&gt;&lt;\/top&gt;&lt;\/xml&gt;\")))\n        .getDocumentElement();\n\n  NamespaceContext namespace = new NamespaceContext() {\n     public String getNamespaceURI(String prefix) {\n        return \"http:\/\/namespace-uri\";\n     }\n\n     public String getPrefix(String namespaceURI) {\n        return null;\n     }\n\n     public Iterator&lt;String&gt; getPrefixes(String namespaceURI) {\n        return null;\n     }\n  };\n\n  \/\/ Then\n  assertThat(testNode, hasXPath(\"\/\/prefix:bottom\", namespace, startsWith(\"val\")));\n}\n<\/pre>\n<p>[ulp id=&#8217;JlDLc89DLzIPpdrn&#8217;]<br \/>\n&nbsp;<\/p>\n<h4><a name=\"instanceOf\"><\/a>3.1.33. instanceOf()<\/h4>\n<p>Matcher which matches if the input object is of the given type.<\/p>\n<pre class=\"brush:java\">\n@Test\npublic void test_instanceOf() throws Exception {\n  \/\/ Given\n  Object string = \"Hello, World!\";\n\n  \/\/ Then\n  assertThat(string, instanceOf(String.class));\n}\n<\/pre>\n<h4><a name=\"isEmptyOrNullString\"><\/a>3.1.34. isEmptyOrNullString()<\/h4>\n<p>Matcher which matches when the input string is either empty or null.<\/p>\n<pre class=\"brush:java\">\n@Test\npublic void test_isEmptyOrNullString() throws Exception {\n  \/\/ Given\n  String emptyString = \";\n  String nullString = null;\n\n  \/\/ Then\n  assertThat(emptyString, isEmptyOrNullString());\n  assertThat(nullString, isEmptyOrNullString());\n}\n<\/pre>\n<h4><a name=\"isEmptyString\"><\/a>3.1.35. isEmptyString()<\/h4>\n<p>Matcher which matches when the input string is empty.<\/p>\n<pre class=\"brush:java\">\n@Test\npublic void test_isEmptyString() throws Exception {\n  \/\/ Given\n  String emptyString = \";\n\n  \/\/ Then\n  assertThat(emptyString, isEmptyString());\n}\n<\/pre>\n<h4><a name=\u201disIn\u201d><\/a>3.1.36. isIn()<\/h4>\n<p>Matcher which matches when the input item is found within the given Collection or Array.<\/p>\n<pre class=\"brush:java\">\n@Test\npublic void test_isIn() throws Exception {\n  \/\/ Given\n  Set&lt;Integer&gt; set = new HashSet&lt;&gt;();\n  set.add(3);\n  set.add(6);\n  set.add(4);\n\n  \/\/ Then\n  assertThat(4, isIn(set));\n}\n<\/pre>\n<h4><a name=\"isOneOf\"><\/a>3.1.37. isOneOf()<\/h4>\n<p>Matcher which matches when the input object is one of the given objects.<\/p>\n<pre class=\"brush:java\">\n@Test\npublic void test_isOneOf() throws Exception {\n  \/\/ Then\n  assertThat(4, isOneOf(3,4,5));\n}\n<\/pre>\n<h4><a name=\u201diterableWithSize\u201d><\/a>3.1.38. iterableWithSize()<\/h4>\n<p>Matchers which match when the input Iterable has the specified size, or matches the specified size matcher.<\/p>\n<p>Actual Value<\/p>\n<pre class=\"brush:java\">\n@Test\npublic void test_iterableWithSize() throws Exception {\n  \/\/ Given\n  Set&lt;Integer&gt; set = new HashSet&lt;&gt;();\n  set.add(3);\n  set.add(6);\n  set.add(4);\n\n  \/\/ Then\n  assertThat(set, iterableWithSize(3));\n}\n<\/pre>\n<p>Matcher<\/p>\n<pre class=\"brush:java\">\n@Test\npublic void test_iterableWithSize_matcher() throws Exception {\n  \/\/ Given\n  Set&lt;Integer&gt; set = new HashSet&lt;&gt;();\n  set.add(3);\n  set.add(6);\n  set.add(4);\n\n  \/\/ Then\n  assertThat(set, iterableWithSize(lessThan(4)));\n}\n<\/pre>\n<h4><a name=\"lessThan\"><\/a>3.1.39. lessThan()<\/h4>\n<p>Matcher which matches Comparable objects where the input object is less than the specified value, using the compareTo method.<\/p>\n<pre class=\"brush:java\">\n@Test\npublic void test_lessThan() throws Exception {\n  \/\/ Then\n  assertThat(\"apple\", lessThan(\"zoo\"));\n}\n<\/pre>\n<h4><a name=\"lessThanOrEqualTo\"><\/a>3.1.40. lessThanOrEqualTo()<\/h4>\n<p>Matcher which matches Comparable objects where the input object is less than or equal to the specified value, using the compareTo method.<\/p>\n<pre class=\"brush:java\">\n@Test\npublic void test_lessThanOrEqualTo() throws Exception {\n   \/\/ Then\n   assertThat(2, lessThanOrEqualTo(2));\n}\n<\/pre>\n<h4><a name=\"not\"><\/a>3.1.41. not()<\/h4>\n<p>Matcher which wraps an existing matcher and inverts it\u2019s matching logic<\/p>\n<pre class=\"brush:java\">\n@Test\npublic void test_not_matcher() throws Exception {\n   \/\/ Then\n   assertThat(\"zoo\", not(lessThan(\"apple\")));\n}\n<\/pre>\n<p>Also an alias for <code>not(equalTo(...))<\/code> when used with a value instead of a matcher<\/p>\n<pre class=\"brush:java\">\n@Test\npublic void test_not_value() throws Exception {\n   \/\/ Then\n   assertThat(\"apple\", not(\"orange\"));\n}\n<\/pre>\n<h4><a name=\"notNullValue\"><\/a>3.1.42. notNullValue()<\/h4>\n<p>Matcher which matches when the input value is not null.<\/p>\n<pre class=\"brush:java\">\n@Test\npublic void test_notNullValue() throws Exception {\n   \/\/ Then\n   assertThat(\"apple\", notNullValue());\n}\n<\/pre>\n<h4><a name=\"nullValue\"><\/a>3.1.43. nullValue()<\/h4>\n<p>Matcher which matches when the input value is null.<\/p>\n<pre class=\"brush:java\">\n@Test\npublic void test_nullValue() throws Exception {\n   \/\/ Given\n   Object nothing = null;\n  \n   \/\/ Then\n   assertThat(nothing, nullValue());\n}\n<\/pre>\n<h4><a name=\"sameInstance\"><\/a>3.1.44. sameInstance()<\/h4>\n<p>Matcher which matches when the input object is the same instance as the specified value.<\/p>\n<pre class=\"brush:java\">\n@Test\npublic void test_sameInstance() throws Exception {\n   \/\/ Given\n   Object one = new Object();\n   Object two = one;\n\n   \/\/ Then\n   assertThat(one, sameInstance(two));\n}\n<\/pre>\n<h4><a name=\"samePropertyValuesAs\"><\/a>3.1.45. samePropertyValuesAs()<\/h4>\n<p>Matchet which matches when the input Bean has the same property values as the specified Bean, i.e. if there are properties on the Bean under test they must exist, and have the same values as the bean being specified in the test condition.<\/p>\n<p>Given the following Java class:<\/p>\n<pre class=\"brush:java\">\npublic class Bean {\n\n    private Integer number;\n    private String text;\n\n    public Integer getNumber() {\n        return number;\n    }\n\n    public void setNumber(Integer number) {\n        this.number = number;\n    }\n\n    public String getText() {\n        return text;\n    }\n\n    public void setText(String text) {\n        this.text = text;\n    }\n}\n<\/pre>\n<p>We can write the following test:<\/p>\n<pre class=\"brush:java\">\n@Test\n    public void test_samePropertyValuesAs() throws Exception {\n        \/\/ Given\n        Bean one = new Bean();\n        one.setText(\"text\");\n        one.setNumber(3);\n\n        Bean two = new Bean();\n        two.setText(\"text\");\n        two.setNumber(3);\n\n        \/\/ Then\n        assertThat(one, samePropertyValuesAs(two));\n    }\n<\/pre>\n<h4><a name=\"startsWith\"><\/a>3.1.46. startsWith()<\/h4>\n<p>Matcher which matches if the input string starts with the given prefix.<\/p>\n<pre class=\"brush:java\">\n@Test\n    public void test_startsWith() throws Exception {\n        \/\/ Given\n        String test = \"Beginnings are important!\";\n\n        \/\/ Then\n        assertThat(test, startsWith(\"Beginning\"));\n    }\n<\/pre>\n<h4><a name=\"stringContainsInOrder\"><\/a>3.1.47. stringContainsInOrder()<\/h4>\n<p>Matcher which matches if the input String contains the substrings in the given Iterable, in the order in which they are returned from the Iterable.<\/p>\n<pre class=\"brush:java\">\n@Test\n    public void test_stringContainsInOrder() throws Exception {\n        \/\/ Given\n        String test = \"Rule number one: two's company, but three's a crowd!\";\n\n        \/\/ Then\n        assertThat(test, stringContainsInOrder(Arrays.asList(\"one\", \"two\", \"three\")));\n    }\n<\/pre>\n<h4><a name=\"theInstance\"><\/a>3.1.48. theInstance()<\/h4>\n<p>Matcher which matches when the input object is the same instance as the specified value. Behaves the same as \u2018sameInstance()\u2019<\/p>\n<pre class=\"brush:java\">\n@Test\npublic void test_theInstance() throws Exception {\n   \/\/ Given\n   Object one = new Object();\n   Object two = one;\n\n   \/\/ Then\n   assertThat(one, theInstance(two));\n}\n<\/pre>\n<h4><a name=\"typeCompatibleWith\"><\/a>3.1.49. typeCompatibleWith()<\/h4>\n<p>Matcher which matches when objects of the input Type can be assigned to references of the specified base Type.<\/p>\n<pre class=\"brush:java\">\n@Test\n    public void test_typeCompatibleWith() throws Exception {\n        \/\/ Given\n        Integer integer = 3;\n\n        \/\/ Then\n        assertThat(integer.getClass(), typeCompatibleWith(Number.class));\n    }\n<\/pre>\n<h3><a name=\"simple_comb\"><\/a>3.2. Simple Matchers Combining Other Matchers<\/h3>\n<p>The following matchers primarily work to combine other matchers.<\/p>\n<h4><a name=\"allOf\"><\/a>3.2.1. allOf()<\/h4>\n<p>Matcher which matches when all of the input Matchers match, behaves like a Logical AND.  Can take individual Matchers or an Iterable of Matchers.<\/p>\n<p>Individual Matchers<\/p>\n<pre class=\"brush:java\">\n@Test\n    public void test_allOf_individual() throws Exception {\n        \/\/ Given\n        String test = \"starting off well, gives content meaning, in the end\";\n\n        \/\/ Then\n        assertThat(test, allOf(startsWith(\"start\"), containsString(\"content\"), endsWith(\"end\")));\n    }\n<\/pre>\n<p>Iterable of Matchers<\/p>\n<pre class=\"brush:java\">\n@Test\n    public void test_allOf_iterable() throws Exception {\n        \/\/ Given\n        String test = \"Hello, world!\";\n\n        List&lt;Matcher&lt;? super String&gt;&gt; matchers = Arrays.asList(containsString(\"world\"), startsWith(\"Hello\"));\n\n        \/\/ Then\n        assertThat(test, allOf(matchers));\n    }\n<\/pre>\n<h4><a name=\"anyOf\"><\/a>3.2.2. anyOf()<\/h4>\n<p>Matcher which matches when any of the input Matchers match, behaves like a Logical OR.  Can take individual Matchers or an Iterable of Matchers.<\/p>\n<p>Individual Matchers<\/p>\n<pre class=\"brush:java\">\n@Test\n    public void test_anyOf_individual() throws Exception {\n        \/\/ Given\n        String test = \"Some things are present, some things are not!\";\n\n        \/\/ Then\n        assertThat(test, anyOf(containsString(\"present\"), containsString(\"missing\")));\n    }\n<\/pre>\n<p>Iterable of Matchers<\/p>\n<pre class=\"brush:java\">\n@Test\n    public void test_anyOf_iterable() throws Exception {\n        \/\/ Given\n        String test = \"Hello, world!\";\n\n        List&lt;Matcher&lt;? super String&gt;&gt; matchers = Arrays.asList(containsString(\"Hello\"), containsString(\"Earth\"));\n\n        \/\/ Then\n        assertThat(test, anyOf(matchers));\n    }\n<\/pre>\n<h4><a name=\"array\"><\/a>3.2.3. array()<\/h4>\n<p>Matcher which matches when the elements of an input array individually match using the specified Matchers, in order.  The number of Matchers must be equal to the size of the array.<\/p>\n<pre class=\"brush:java\">\n@Test\n    public void test_array() throws Exception {\n        \/\/ Given\n        String[] test = {\"To be\", \"or not to be\", \"that is the question!\"};\n\n        \/\/ Then\n        assertThat(test, array(startsWith(\"To\"), containsString(\"not\"), instanceOf(String.class)));\n    }\n<\/pre>\n<h4><a name=\"both\"><\/a>3.2.4. both()<\/h4>\n<p>Matcher which, when used in combination with it\u2019s combinable matcher .and() will match when both specified matchers match.<\/p>\n<pre class=\"brush:java\">\n@Test\n    public void test_both() throws Exception {\n        \/\/ Given\n        String test = \"Hello, world!\";\n\n        \/\/ Then\n        assertThat(test, both(startsWith(\"Hello\")).and(endsWith(\"world!\")));\n    }\n<\/pre>\n<h4><a name=\"either\"><\/a>3.2.5. either()<\/h4>\n<p>Matcher which, when used in combination with it\u2019s combinable matcher .or() will match when either if the specified matchers match.<\/p>\n<pre class=\"brush:java\">\n@Test\n    public void test_either() throws Exception {\n        \/\/ Given\n        String test = \"Hello, world!\";\n\n        \/\/ Then\n        assertThat(test, either(startsWith(\"Hello\")).or(endsWith(\"universe!\")));\n    }\n<\/pre>\n<h4><a name=\"is\"><\/a>3.2.6. is()<\/h4>\n<p>Matcher which matches when it\u2019s input matcher matches, used simply for convenience and to make assertions read more like English.<\/p>\n<pre class=\"brush:java\">\n@Test\n    public void test_is_matcher() throws Exception {\n        \/\/ Given\n        Integer test = 5;\n\n        \/\/ Then\n        assertThat(test, is(greaterThan(3)));\n    }\n<\/pre>\n<p>Also used as an alias for <code>is(equalTo(...))<\/code>, similar to <code>not(...)<\/code> and <code>not(equalTo(...))<\/code><\/p>\n<pre class=\"brush:java\">\n@Test\n    public void test_is_value() throws Exception {\n        \/\/ Given\n        Integer test = 5;\n\n        \/\/ Then\n        assertThat(test, is(5));\n    }\n<\/pre>\n<h4><a name=\u201ddescribedAs\u201d><\/a>3.2.7. describedAs()<\/h4>\n<p>Matcher which is used to override the failure output of another matcher.  Used when a custom failure output is needed.  Arguments are the failure message, the original Matcher and then any values which will be formatted into the failure message using placeholders %0, %1, %2&#8230;<\/p>\n<pre class=\"brush:java\">\n@Test\n    public void test_describedAs() throws Exception {\n        \/\/ Given\n        Integer actual = 7;\n        Integer expected = 10;\n\n        \/\/ Then\n        assertThat(actual, describedAs(\"input &gt; %0\", greaterThan(expected), expected));\n    }\n<\/pre>\n<h2><a name=\"conclusion\"><\/a>4. Conclusion<\/h2>\n<p>We have now visited with all the Matchers defined in Hamcrest and seen examples of each one in action.  There are lot of very useful and powerful Matchers in the library, particularly when used in combination with each other.  But sometimes we need to do further than what\u2019s there already.  In the <a href=\"http:\/\/www.javacodegeeks.com\/2015\/11\/custom-hamcrest-matchers.html\">next tutorial<\/a> we will examine how to create our own custom Matchers, to extend Hamcrest and make it even more useful!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article is part of our Academy Course titled Testing with Mockito. In this course, you will dive into the magic of Mockito. You will learn about Mocks, Spies and Partial Mocks, and their corresponding Stubbing behaviour. You will also see the process of Verification with Test Doubles and Object Matchers. Finally, Test Driven Development &hellip;<\/p>\n","protected":false},"author":582,"featured_media":186,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[460,273],"class_list":["post-49089","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-java","tag-mockito","tag-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Hamcrest matchers tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"This article is part of our Academy Course titled Testing with Mockito. In this course, you will dive into the magic of Mockito. You will learn about\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hamcrest matchers tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"This article is part of our Academy Course titled Testing with Mockito. In this course, you will dive into the magic of Mockito. You will learn about\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2015-11-15T21:05:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-13T09:10:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mockito-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Hugh Hamill\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hugh Hamill\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/hamcrest-matchers-tutorial.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/hamcrest-matchers-tutorial.html\"},\"author\":{\"name\":\"Hugh Hamill\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/16859fadb54e0a7d918890100afa9c3e\"},\"headline\":\"Hamcrest matchers tutorial\",\"datePublished\":\"2015-11-15T21:05:31+00:00\",\"dateModified\":\"2023-12-13T09:10:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/hamcrest-matchers-tutorial.html\"},\"wordCount\":2643,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/hamcrest-matchers-tutorial.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mockito-logo.jpg\",\"keywords\":[\"Mockito\",\"Testing\"],\"articleSection\":[\"Core Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/hamcrest-matchers-tutorial.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/hamcrest-matchers-tutorial.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/hamcrest-matchers-tutorial.html\",\"name\":\"Hamcrest matchers tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/hamcrest-matchers-tutorial.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/hamcrest-matchers-tutorial.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mockito-logo.jpg\",\"datePublished\":\"2015-11-15T21:05:31+00:00\",\"dateModified\":\"2023-12-13T09:10:32+00:00\",\"description\":\"This article is part of our Academy Course titled Testing with Mockito. In this course, you will dive into the magic of Mockito. You will learn about\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/hamcrest-matchers-tutorial.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/hamcrest-matchers-tutorial.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/hamcrest-matchers-tutorial.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mockito-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mockito-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/hamcrest-matchers-tutorial.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/core-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Hamcrest matchers tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/16859fadb54e0a7d918890100afa9c3e\",\"name\":\"Hugh Hamill\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g\",\"caption\":\"Hugh Hamill\"},\"description\":\"Hugh is a Senior Software Engineer and Certified Scrum Master based in Galway, Ireland. He achieved his B.Sc. in Applied Computing from Waterford Institute of Technology in 2002 and has been working in industry since then. He has worked for a several large blue chip software companies listed on both the NASDAQ and NYSE.\",\"sameAs\":[\"http:\\\/\\\/www.doubleh.ie\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/hugh-hamill\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Hamcrest matchers tutorial - Java Code Geeks","description":"This article is part of our Academy Course titled Testing with Mockito. In this course, you will dive into the magic of Mockito. You will learn about","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html","og_locale":"en_US","og_type":"article","og_title":"Hamcrest matchers tutorial - Java Code Geeks","og_description":"This article is part of our Academy Course titled Testing with Mockito. In this course, you will dive into the magic of Mockito. You will learn about","og_url":"https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2015-11-15T21:05:31+00:00","article_modified_time":"2023-12-13T09:10:32+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mockito-logo.jpg","type":"image\/jpeg"}],"author":"Hugh Hamill","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Hugh Hamill","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html"},"author":{"name":"Hugh Hamill","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/16859fadb54e0a7d918890100afa9c3e"},"headline":"Hamcrest matchers tutorial","datePublished":"2015-11-15T21:05:31+00:00","dateModified":"2023-12-13T09:10:32+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html"},"wordCount":2643,"commentCount":2,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mockito-logo.jpg","keywords":["Mockito","Testing"],"articleSection":["Core Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html","url":"https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html","name":"Hamcrest matchers tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mockito-logo.jpg","datePublished":"2015-11-15T21:05:31+00:00","dateModified":"2023-12-13T09:10:32+00:00","description":"This article is part of our Academy Course titled Testing with Mockito. In this course, you will dive into the magic of Mockito. You will learn about","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mockito-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mockito-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/hamcrest-matchers-tutorial.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/core-java"},{"@type":"ListItem","position":4,"name":"Hamcrest matchers tutorial"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/16859fadb54e0a7d918890100afa9c3e","name":"Hugh Hamill","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g","caption":"Hugh Hamill"},"description":"Hugh is a Senior Software Engineer and Certified Scrum Master based in Galway, Ireland. He achieved his B.Sc. in Applied Computing from Waterford Institute of Technology in 2002 and has been working in industry since then. He has worked for a several large blue chip software companies listed on both the NASDAQ and NYSE.","sameAs":["http:\/\/www.doubleh.ie"],"url":"https:\/\/www.javacodegeeks.com\/author\/hugh-hamill"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/49089","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/582"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=49089"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/49089\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/186"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=49089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=49089"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=49089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}