{"id":47173,"date":"2017-06-09T11:00:41","date_gmt":"2017-06-09T08:00:41","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=47173"},"modified":"2019-03-20T13:52:38","modified_gmt":"2019-03-20T11:52:38","slug":"junit-basematcher-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/","title":{"rendered":"JUnit BaseMatcher Example"},"content":{"rendered":"<p>In this tutorial, we shall show users JUnit BaseMatcher Example. It is very common to test the matches in JUnit. It provides many inbuilt matchers for our testing.<\/p>\n<p>We have seen in our previous <a href=\"https:\/\/examples.javacodegeeks.com\/author\/vinod-kashyap\/\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>tutorials<\/strong><\/a> how we can test our methods with the help of matchers.<\/p>\n<p>In <a href=\"https:\/\/examples.javacodegeeks.com\/core-java\/junit\/junit-hamcrest-example\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><strong>JUnit Hamcrest Example<\/strong><\/a> we have seen how JUnit matchers works. In this tutorial we will focus on <strong>BaseMatcher<\/strong> class of JUnit.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;\n<\/p>\n<h2>1. Introduction<\/h2>\n<p><a href=\"http:\/\/junit.org\/junit4\/javadoc\/4.12\/org\/hamcrest\/BaseMatcher.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><strong>BaseMatcher<\/strong><\/a> is the base class for all <a href=\"http:\/\/junit.org\/junit4\/javadoc\/4.12\/org\/hamcrest\/Matcher.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><strong>Matcher<\/strong><\/a> implementations. There is one point that is mentioned in API. Check the tip below.<\/p>\n<div class=\"tip\"><strong>Tip<\/strong><br \/>\nWe should not implement directly the <strong>Matcher<\/strong> class. Instead we should extend <strong>BaseMatcher<\/strong> class.<\/div>\n<h3>1.1 Class Hierarchy<\/h3>\n<p>This figure describes the class hierarchy of the <strong>BaseMatcher<\/strong> class. Boxes that are marked with orange are interfaces and those that are marked with blue are classes.<\/p>\n<p><figure id=\"attachment_47195\" aria-describedby=\"caption-attachment-47195\" style=\"width: 566px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/class_hierarchy.png\"><img decoding=\"async\" class=\"size-full wp-image-47195\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/class_hierarchy.png\" alt=\"Class Hierarchy\" width=\"566\" height=\"626\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/class_hierarchy.png 566w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/class_hierarchy-271x300.png 271w\" sizes=\"(max-width: 566px) 100vw, 566px\" \/><\/a><figcaption id=\"caption-attachment-47195\" class=\"wp-caption-text\">Figure 1: Class Hierarchy<\/figcaption><\/figure><\/p>\n<h2>2. Technologies Used<\/h2>\n<p>We will be using the following technologies while creating this example.<\/p>\n<ul>\n<li>Java 1.8<\/li>\n<li>JUnit 4.12<\/li>\n<li>Eclipse<\/li>\n<li>Maven<\/li>\n<\/ul>\n<h2>3. Project Setup<\/h2>\n<div class=\"tip\"><strong>Tip<\/strong><br \/>\nYou may skip project creation and jump directly to the <a href=\"#code\"><strong>beginning of the example<\/strong><\/a> below.<\/div>\n<p>We will create a Maven project. <a href=\"http:\/\/maven.apache.org\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><strong>Maven<\/strong><\/a> is a dependency management tool and helps us to get all required jar files for this example.<br \/>\nOpen eclipse. Click on <strong>File -&gt; New -&gt; Maven Project<\/strong>.<br \/>\nSimply click on check mark as shown and click on the <strong>Next<\/strong> button.<\/p>\n<p><figure id=\"attachment_47200\" aria-describedby=\"caption-attachment-47200\" style=\"width: 725px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/junit-basematcher-setup-1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-47200\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/junit-basematcher-setup-1.jpg\" alt=\"JUnit BaseMatcher Example Setup 1\" width=\"725\" height=\"503\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/junit-basematcher-setup-1.jpg 725w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/junit-basematcher-setup-1-300x208.jpg 300w\" sizes=\"(max-width: 725px) 100vw, 725px\" \/><\/a><figcaption id=\"caption-attachment-47200\" class=\"wp-caption-text\">Figure 2: JUnit BaseMatcher Example Setup 1<\/figcaption><\/figure><\/p>\n<p>On this screen fill in the required details as shown and click on the <strong>Finish<\/strong> button.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><figure id=\"attachment_47201\" aria-describedby=\"caption-attachment-47201\" style=\"width: 720px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/junit-basematcher-setup-2.jpg\"><img decoding=\"async\" class=\"size-full wp-image-47201\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/junit-basematcher-setup-2.jpg\" alt=\"JUnit BaseMatcher Example Setup 2\" width=\"720\" height=\"661\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/junit-basematcher-setup-2.jpg 720w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/junit-basematcher-setup-2-300x275.jpg 300w\" sizes=\"(max-width: 720px) 100vw, 720px\" \/><\/a><figcaption id=\"caption-attachment-47201\" class=\"wp-caption-text\">Figure 3: JUnit BaseMatcher Example Setup 2<\/figcaption><\/figure><\/p>\n<p>With the <strong>Finish<\/strong> button we are ready with the blank Maven project.<br \/>\n<span id=\"code\"><\/span><\/p>\n<h2>4. JUnit BaseMatcher Example<\/h2>\n<p>Before starting the programming part we need to change the <strong>pom.xml<\/strong>. Simply paste these lines in <strong>pom.xml<\/strong>.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml;wrap-lines:false\">    &lt;dependencies&gt;\n        &lt;dependency&gt;\n            &lt;groupId&gt;junit&lt;\/groupId&gt;\n            &lt;artifactId&gt;junit&lt;\/artifactId&gt;\n            &lt;version&gt;4.12&lt;\/version&gt;\n            &lt;scope&gt;test&lt;\/scope&gt;\n        &lt;\/dependency&gt;\n    &lt;\/dependencies&gt;\n    &lt;build&gt;\n        &lt;finalName&gt;junitbasematcher&lt;\/finalName&gt;\n        &lt;plugins&gt;\n            &lt;plugin&gt;\n                &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\n                &lt;artifactId&gt;maven-compiler-plugin&lt;\/artifactId&gt;\n                &lt;version&gt;2.5.1&lt;\/version&gt;\n                &lt;inherited&gt;true&lt;\/inherited&gt;\n                &lt;configuration&gt;\n                    &lt;source&gt;1.8&lt;\/source&gt;\n                    &lt;target&gt;1.8&lt;\/target&gt;\n                &lt;\/configuration&gt;\n            &lt;\/plugin&gt;\n        &lt;\/plugins&gt;\n    &lt;\/build&gt;\n<\/pre>\n<p>Here in this file, we are simply adding a dependency for JUnit and also specifying that we need <strong>Java 8<\/strong> for build and compilation.<\/p>\n<h3>4.1 Java classes<\/h3>\n<p>Let&#8217;s create a custom matcher by extending the <strong>BaseMatcher<\/strong> class.<br \/>\nThis is a custom matcher that will test for a prime number.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>IsPrime.java<\/em><\/span><\/p>\n<pre class=\"brush:java;wrap-lines:false;highlight:[8,11,16,21,55]\">package com.javacodegeeks;\n\nimport org.hamcrest.BaseMatcher;\nimport org.hamcrest.Description;\nimport org.hamcrest.Factory;\nimport org.hamcrest.Matcher;\n\npublic class IsPrime&lt;T&gt; extends BaseMatcher&lt;T&gt; {\n\n    @Override\n    public boolean matches(Object actualValue) {\n        return isPrime(actualValue);\n    }\n\n    @Override\n    public void describeTo(Description description) {\n        description.appendValue(\"Prime Number.\");\n    }\n\n    @Override\n    public void describeMismatch(Object item, Description description) {\n        description.appendValue(item + \" is not a Prime Number.\");\n    }\n\n    private static boolean isPrime(Object actual) {\n        if (actual == null) {\n            return false;\n        }\n\n        if (actual instanceof Integer) {\n            int num = ((Integer) actual).intValue();\n            for (int i = 2; i &lt;= num \/ 2; i++) {\n                if (((Integer) actual).intValue() % i == 0) {\n                    return false;\n                }\n            }\n            return true;\n        } else if (actual instanceof String) {\n            try {\n                int num = (Integer.valueOf((String) actual)).intValue();\n                for (int i = 2; i &lt;= num \/ 2; i++) {\n                    if (num % i == 0) {\n                        return false;\n                    }\n                }\n                return true;\n            } catch (NumberFormatException nfe) {\n                return false;\n            }\n        }\n        return false;\n    }\n\n    @Factory\n    public static &lt;T&gt; Matcher&lt;T&gt; isPrime() {\n        return new IsPrime&lt;T&gt;();\n    }\n}\n<\/pre>\n<p>Let&#8217;s analyze the above class and its methods. We have extended the <strong>BaseMatcher<\/strong> class (<strong>see line 8<\/strong>) to create our own Matcher.<br \/>\n<strong>Line 11<\/strong>: The <code>matches()<\/code> method will match for the condition. This method is overridden from <strong>Matcher<\/strong> interface. It evaluates the matcher for argument item.<br \/>\n<strong>Line 16<\/strong>: The <code>describeTo()<\/code> method will print the required description. This method is overridden from <strong>SelfDescribing<\/strong> interface. It will generate a description of the object.<br \/>\n<strong>Line 21<\/strong>: The <code>describeMismatch()<\/code> method will print a message when ever match is not fulfilled. This method is overridden from <strong>BaseMatcher<\/strong> class and it overrides from <strong>Matcher<\/strong> class. It will generate a description of why the matcher has not accepted the item.<br \/>\n<strong>Line 55<\/strong>: This is the main method that is called from outside the class. In return it will call <code>matches()<\/code> method which is written at <strong>line 11<\/strong>.[ulp id=&#8217;ODQaBEw1BIbHApZq&#8217;]<\/p>\n<p>Next, we will create a test class to test out custom matcher.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>IsPrimeTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java;wrap-lines:false;highlight:[12]\">package com.javacodegeeks;\n\nimport static com.javacodegeeks.IsPrime.isPrime;\nimport static org.junit.Assert.assertThat;\n\nimport org.junit.Test;\n\npublic class IsPrimeTest {\n\n    @Test\n    public void testIsPrime() {\n        assertThat(4, isPrime());\n    }\n}\n\n<\/pre>\n<p>Since the value <strong>4<\/strong> at <strong>line 12<\/strong> is not a prime it will display a failure message like this:<\/p>\n<p><figure id=\"attachment_47202\" aria-describedby=\"caption-attachment-47202\" style=\"width: 603px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/fail-output.jpg\"><img decoding=\"async\" class=\"size-full wp-image-47202\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/fail-output.jpg\" alt=\"Test Fail\" width=\"603\" height=\"361\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/fail-output.jpg 603w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/fail-output-300x180.jpg 300w\" sizes=\"(max-width: 603px) 100vw, 603px\" \/><\/a><figcaption id=\"caption-attachment-47202\" class=\"wp-caption-text\">Figure 4: Test Fail<\/figcaption><\/figure><\/p>\n<p>It is clear that in class <code>IsPrime<\/code> above at <strong>line 16<\/strong>, we have defined a message. In Figure 4, we can see that message is showing as <code>Expected: \"Prime Number.\"<\/code>.<br \/>\nSimilarly failure message as defined at <strong>line 21<\/strong> in class <code>IsPrime<\/code> is shown as <code>but:\"4 is not a Prime Number.\"<\/code><br \/>\nSo, we can see that we have defined our own messages.<\/p>\n<p>Otherwise, if we run with a value <strong>2<\/strong>, which is a prime we will get a success.<\/p>\n<p><figure id=\"attachment_47203\" aria-describedby=\"caption-attachment-47203\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/pass-output.jpg\"><img decoding=\"async\" class=\"size-full wp-image-47203\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/pass-output.jpg\" alt=\"Test Pass\" width=\"600\" height=\"248\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/pass-output.jpg 600w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/pass-output-300x124.jpg 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-47203\" class=\"wp-caption-text\">Figure 5: Test Pass<\/figcaption><\/figure><\/p>\n<h2>5. Conclusion<\/h2>\n<p>We have learned about the class <strong>BaseMatcher<\/strong> of JUnit. It is very important class and works as a base class for many matchers in JUnit. We have seen how we can create our own custom matcher and we have also learned how to use it.<\/p>\n<p>If you look into the classes of JUnit you will see the same behavior as described here. We have also learned that <strong>we should not directly implement the Matcher interface but extend the BaseMatcher class<\/strong>, which is of course an Abstract class.<\/p>\n<h2>6. Download the Eclipse Project<\/h2>\n<p>This is JUnit BaseMatcher Example.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/junitbasematcher.zip\"><strong>JUnitBaseMatcher.zip<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we shall show users JUnit BaseMatcher Example. It is very common to test the matches in JUnit. It provides many inbuilt matchers for our testing. We have seen in our previous tutorials how we can test our methods with the help of matchers. In JUnit Hamcrest Example we have seen how JUnit &hellip;<\/p>\n","protected":false},"author":112,"featured_media":6678,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[1032],"class_list":["post-47173","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-junit","tag-junit"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JUnit BaseMatcher Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this tutorial we shall show users JUnit BaseMatcher Example. BaseMatcher is the base class for all Matcher implementations. We can create custom matchers\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JUnit BaseMatcher Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this tutorial we shall show users JUnit BaseMatcher Example. BaseMatcher is the base class for all Matcher implementations. We can create custom matchers\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2017-06-09T08:00:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-20T11:52:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-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=\"Vinod Kumar Kashyap\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vinodkashyap\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vinod Kumar Kashyap\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/\"},\"author\":{\"name\":\"Vinod Kumar Kashyap\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/1d6281e8235e49b5b8614621c2445d2c\"},\"headline\":\"JUnit BaseMatcher Example\",\"datePublished\":\"2017-06-09T08:00:41+00:00\",\"dateModified\":\"2019-03-20T11:52:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/\"},\"wordCount\":723,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"keywords\":[\"junit\"],\"articleSection\":[\"junit\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/\",\"name\":\"JUnit BaseMatcher Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"datePublished\":\"2017-06-09T08:00:41+00:00\",\"dateModified\":\"2019-03-20T11:52:38+00:00\",\"description\":\"In this tutorial we shall show users JUnit BaseMatcher Example. BaseMatcher is the base class for all Matcher implementations. We can create custom matchers\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"junit\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/junit\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"JUnit BaseMatcher Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/1d6281e8235e49b5b8614621c2445d2c\",\"name\":\"Vinod Kumar Kashyap\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a11634ec460c849e8631b740af1b75cb68c9c58d5c2339c21bcd95f55b9af4f5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a11634ec460c849e8631b740af1b75cb68c9c58d5c2339c21bcd95f55b9af4f5?s=96&d=mm&r=g\",\"caption\":\"Vinod Kumar Kashyap\"},\"description\":\"Vinod is Sun Certified and love to work in Java and related technologies. Having more than 13 years of experience, he had developed software's including technologies like Java, Hibernate, Struts, Spring, HTML 5, jQuery, CSS, Web Services, MongoDB, AngularJS, AWS. He is also a JUG Leader of Chandigarh Java User Group.\",\"sameAs\":[\"http:\/\/www.vinodkashyap.com\/\",\"https:\/\/www.instagram.com\/vinodkashyap\/\",\"https:\/\/in.linkedin.com\/in\/vinodkashyap\",\"https:\/\/in.pinterest.com\/vinodkashyap\/\",\"https:\/\/x.com\/vinodkashyap\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/vinod-kashyap\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JUnit BaseMatcher Example - Java Code Geeks","description":"In this tutorial we shall show users JUnit BaseMatcher Example. BaseMatcher is the base class for all Matcher implementations. We can create custom matchers","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:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/","og_locale":"en_US","og_type":"article","og_title":"JUnit BaseMatcher Example - Java Code Geeks","og_description":"In this tutorial we shall show users JUnit BaseMatcher Example. BaseMatcher is the base class for all Matcher implementations. We can create custom matchers","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2017-06-09T08:00:41+00:00","article_modified_time":"2019-03-20T11:52:38+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","type":"image\/jpeg"}],"author":"Vinod Kumar Kashyap","twitter_card":"summary_large_image","twitter_creator":"@vinodkashyap","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Vinod Kumar Kashyap","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/"},"author":{"name":"Vinod Kumar Kashyap","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/1d6281e8235e49b5b8614621c2445d2c"},"headline":"JUnit BaseMatcher Example","datePublished":"2017-06-09T08:00:41+00:00","dateModified":"2019-03-20T11:52:38+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/"},"wordCount":723,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","keywords":["junit"],"articleSection":["junit"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/","name":"JUnit BaseMatcher Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","datePublished":"2017-06-09T08:00:41+00:00","dateModified":"2019-03-20T11:52:38+00:00","description":"In this tutorial we shall show users JUnit BaseMatcher Example. BaseMatcher is the base class for all Matcher implementations. We can create custom matchers","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-basematcher-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"junit","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/junit\/"},{"@type":"ListItem","position":5,"name":"JUnit BaseMatcher Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/1d6281e8235e49b5b8614621c2445d2c","name":"Vinod Kumar Kashyap","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a11634ec460c849e8631b740af1b75cb68c9c58d5c2339c21bcd95f55b9af4f5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a11634ec460c849e8631b740af1b75cb68c9c58d5c2339c21bcd95f55b9af4f5?s=96&d=mm&r=g","caption":"Vinod Kumar Kashyap"},"description":"Vinod is Sun Certified and love to work in Java and related technologies. Having more than 13 years of experience, he had developed software's including technologies like Java, Hibernate, Struts, Spring, HTML 5, jQuery, CSS, Web Services, MongoDB, AngularJS, AWS. He is also a JUG Leader of Chandigarh Java User Group.","sameAs":["http:\/\/www.vinodkashyap.com\/","https:\/\/www.instagram.com\/vinodkashyap\/","https:\/\/in.linkedin.com\/in\/vinodkashyap","https:\/\/in.pinterest.com\/vinodkashyap\/","https:\/\/x.com\/vinodkashyap"],"url":"https:\/\/examples.javacodegeeks.com\/author\/vinod-kashyap\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/47173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/112"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=47173"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/47173\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/6678"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=47173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=47173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=47173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}