{"id":25195,"date":"2015-07-17T11:00:33","date_gmt":"2015-07-17T08:00:33","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=25195"},"modified":"2019-03-21T12:34:12","modified_gmt":"2019-03-21T10:34:12","slug":"junit-assertthat-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/","title":{"rendered":"JUnit AssertThat Example"},"content":{"rendered":"<h2>1. Introduction<\/h2>\n<p>The <code><a href=\"http:\/\/junit.sourceforge.net\/javadoc\/org\/junit\/Assert.html#assertThat(T, org.hamcrest.Matcher)\" target=\"_blank\" rel=\"noopener noreferrer\">assertThat<\/a><\/code> is one of the JUnit methods from the Assert object that can be used to check if a specific value match to an expected one.<\/p>\n<p>It primarily accepts 2 parameters. First one if the actual value and the second is a matcher object. It will then try to compare this two and returns a boolean result if its a match or not. Example of it&#8217;s usage as per below.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;\n<\/p>\n<h2>2. The Source Code<\/h2>\n<p><span style=\"text-decoration: underline\"><em>JUnitTestAssertThatAssertions.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.areyes1.junitassertrue.sample;\n\nimport static org.junit.Assert.*;\nimport static org.hamcrest.CoreMatchers.*;\nimport org.junit.Before;\nimport org.junit.Test;\n\npublic class JUnitTestAssertThatAssertions {\n\t\n\tint totalNumberOfApplicants = 0;\n\t\n\t@Before\n\tpublic void setData(){\n\t\tthis.totalNumberOfApplicants = 9;\n\t}\n\t\n\t@Test\n\tpublic void testAssertThatEqual() {\n\t\tassertThat(\"123\",is(\"123\"));\n\t}\n\t\n\t@Test\n\tpublic void testAssertThatNotEqual() {\n\t\tassertThat(totalNumberOfApplicants,is(123));\n\t}\n\t\n\t@Test\n\tpublic void testAssertThatObject() {\n\t\tassertThat(\"123\",isA(String.class));\n\t}\n\t\n\t@Test\n\tpublic void testAssertThatWMessage(){\n\t\tassertThat(\"They are not equal!\",\"123\",is(\"1234\"));\n\t}\n}\n\n\n<\/pre>\n<p>The example shown above uses <code><a href=\"http:\/\/hamcrest.org\/JavaHamcrest\/javadoc\/1.3\/\" target=\"_blank\" rel=\"noopener noreferrer\">is<\/a><\/code> and <code><a href=\"http:\/\/hamcrest.org\/JavaHamcrest\/javadoc\/1.3\/\" target=\"_blank\" rel=\"noopener noreferrer\">isA<\/a><\/code> method from the hamcrest core to return a matcher object given the value. This is then used by the <a href=\"http:\/\/junit.sourceforge.net\/javadoc\/org\/junit\/Assert.html#assertThat(T, org.hamcrest.Matcher)\" target=\"_blank\" rel=\"noopener noreferrer\">assertThat<\/a> method that will then return a boolean result of the comparison.<\/p>\n<p>Here&#8217;s the output:<\/p>\n<p><figure id=\"attachment_25198\" aria-describedby=\"caption-attachment-25198\" style=\"width: 1074px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/assertthat.jpg\"><img decoding=\"async\" class=\"size-full wp-image-25198\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/assertthat.jpg\" alt=\"Figure 1.0 AssertThat output\" width=\"1074\" height=\"286\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/assertthat.jpg 1074w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/assertthat-300x80.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/assertthat-1024x273.jpg 1024w\" sizes=\"(max-width: 1074px) 100vw, 1074px\" \/><\/a><figcaption id=\"caption-attachment-25198\" class=\"wp-caption-text\">Figure 1.0 AssertThat output<\/figcaption><\/figure><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Aside from the example above, there are far more methods that can be used to rigorously test one&#8217;s code. JUnits own hamcrest api has incorporate core, logical and object methods for this purpose.<\/p>\n<h3>2.1 Core Matchers<\/h3>\n<p>Before you start implementing your own Matcher&#8217;s, you should look at the core matchers that come with JUnit already. Here is a list of the matcher methods:<\/p>\n<h4>Core<\/h4>\n<ul>\n<li><a href=\"http:\/\/hamcrest.org\/JavaHamcrest\/javadoc\/1.3\/\" target=\"_blank\" rel=\"noopener noreferrer\"><code>any()<\/code><\/a> Matches any object passed to it.<\/li>\n<li><a href=\"http:\/\/hamcrest.org\/JavaHamcrest\/javadoc\/1.3\/\" target=\"_blank\" rel=\"noopener noreferrer\"><code>is()<\/code><\/a> A matcher that checks if the given objects are equal.<\/li>\n<li><a href=\"http:\/\/hamcrest.org\/JavaHamcrest\/javadoc\/1.3\/\" target=\"_blank\" rel=\"noopener noreferrer\"><code>describedAs()<\/code><\/a> adds a description to the matcher<\/li>\n<\/ul>\n<h4>Logical<\/h4>\n<ul>\n<li><a href=\"http:\/\/hamcrest.org\/JavaHamcrest\/javadoc\/1.3\/\" target=\"_blank\" rel=\"noopener noreferrer\"><code>allOf()<\/code><\/a> Takes an array of matchers and must all match the expected object.<\/li>\n<li><a href=\"http:\/\/hamcrest.org\/JavaHamcrest\/javadoc\/1.3\/\" target=\"_blank\" rel=\"noopener noreferrer\"><code>anyOf()<\/code><\/a> Takes an array of matcher and must match at least one of the matchers must report that it matches the target object.<\/li>\n<li><a href=\"http:\/\/hamcrest.org\/JavaHamcrest\/javadoc\/1.3\/\" target=\"_blank\" rel=\"noopener noreferrer\"><code>not()<\/code><\/a> Check if the object negates what was passed.<\/li>\n<\/ul>\n<h4>Object<\/h4>\n<ul>\n<li><a href=\"http:\/\/hamcrest.org\/JavaHamcrest\/javadoc\/1.3\/\" target=\"_blank\" rel=\"noopener noreferrer\"><code>equalTo()<\/code><\/a> Equality check.<\/li>\n<li><a href=\"http:\/\/hamcrest.org\/JavaHamcrest\/javadoc\/1.3\/\" target=\"_blank\" rel=\"noopener noreferrer\"><code>instanceOf()<\/code><\/a> Check if an object is an instance of a given\/expected object.<\/li>\n<li><a href=\"http:\/\/hamcrest.org\/JavaHamcrest\/javadoc\/1.3\/\" target=\"_blank\" rel=\"noopener noreferrer\"><code>notNullValue()<\/code><\/a> Check if the passed value is not null<\/li>\n<li><a href=\"http:\/\/hamcrest.org\/JavaHamcrest\/javadoc\/1.3\/\" target=\"_blank\" rel=\"noopener noreferrer\"><code>nullValue()<\/code><\/a> Tests whether the given object is null or not null.<\/li>\n<li><a href=\"http:\/\/hamcrest.org\/JavaHamcrest\/javadoc\/1.3\/\" target=\"_blank\" rel=\"noopener noreferrer\"><code>sameInstance()<\/code><\/a> Tests if the given object is the exact same instance as another.<\/li>\n<\/ul>\n<p>The list above can all be used on <a href=\"http:\/\/junit.sourceforge.net\/javadoc\/org\/junit\/Assert.html#assertThat(T, org.hamcrest.Matcher)\" target=\"_blank\" rel=\"noopener noreferrer\"><code>assertThat<\/code><\/a> method. It gives a wide range of possible scenarios to fully regress the extend of your algorithm, logic or processes of your application.[ulp id=&#8217;ODQaBEw1BIbHApZq&#8217;]<\/p>\n<h2>3. Bonus: Custom Matchers for your <code>assertThat<\/code><\/h2>\n<p>You can actually create our own matcher and simply using that on your junit test case. See example of the custom matcher below.<\/p>\n<p><span style=\"text-decoration: underline\"><em>CustomMatcher.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.areyes1.junitassertthat.sample;\n\nimport org.hamcrest.BaseMatcher;\nimport org.hamcrest.Description;\nimport org.hamcrest.Matcher;\n\npublic class CustomMatcher {\n\tpublic static Matcher matches(final Object expected){\n\t\t\treturn new BaseMatcher() {\n\t\t\t\tprotected Object expectedObject = expected;\n\t\t\t\tpublic boolean matches(Object item) {\n\t\t\t\t\treturn expectedObject.equals(item);\n\t\t\t\t}\n\t\t\t\tpublic void describeTo(Description description) {\n\t\t\t\t\tdescription.appendText(expectedObject.toString());\n\t\t\t\t}\n\t\t\t};\n\t}\n}\n<\/pre>\n<p>We can then use that matcher as part of our Junit Test source.<\/p>\n<p><span style=\"text-decoration: underline\"><em>JUnitTestAssertThatCustomMatcher.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.areyes1.junitassertthat.sample;\n\nimport static org.junit.Assert.*;\nimport static com.areyes1.junitassertthat.sample.CustomMatcher.*;\nimport static org.hamcrest.CoreMatchers.*;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport org.junit.Before;\nimport org.junit.Test;\n\npublic class JUnitTestAssertThatCustomMatcher {\n\n\tArrayList listOfValidStrings = new ArrayList();\n\tprivate String inputValue = new String(\"Hello\");\n\t@Before\n\tpublic void setData(){\n\t\tlistOfValidStrings.add(\"object_1\");\n\t\tlistOfValidStrings.add(\"object_2\");\n\t\tlistOfValidStrings.add(\"object_3\");\n\t}\n\t\n\t@Test\n\tpublic void testLogic(){\n\t\tassertThat(inputValue,matches(\"Hello\"));\n\t}\n}\n\n<\/pre>\n<p>Here&#8217;s the output:<\/p>\n<p><figure id=\"attachment_25214\" aria-describedby=\"caption-attachment-25214\" style=\"width: 556px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/custom_matcher.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/custom_matcher.jpg\" alt=\"Figure 2.0 AssertThat output\" width=\"556\" height=\"208\" class=\"size-full wp-image-25214\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/custom_matcher.jpg 556w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/custom_matcher-300x112.jpg 300w\" sizes=\"(max-width: 556px) 100vw, 556px\" \/><\/a><figcaption id=\"caption-attachment-25214\" class=\"wp-caption-text\">Figure 2.0 AssertThat output<\/figcaption><\/figure><\/p>\n<h2>4. Download the Eclipse project<\/h2>\n<p>This was an example of JUnit <a href=\"http:\/\/junit.sourceforge.net\/javadoc\/org\/junit\/Assert.html#assertThat(T, org.hamcrest.Matcher)\" target=\"_blank\" rel=\"noopener noreferrer\"><code>assertThat<\/code><\/a><\/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\/2015\/07\/junit-assertthat-example2.zip\"><b>junit-assertthat-example<\/b><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction The assertThat is one of the JUnit methods from the Assert object that can be used to check if a specific value match to an expected one. It primarily accepts 2 parameters. First one if the actual value and the second is a matcher object. It will then try to compare this two &hellip;<\/p>\n","protected":false},"author":41,"featured_media":6678,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-25195","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-junit"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JUnit AssertThat Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"1. Introduction The assertThat is one of the JUnit methods from the Assert object that can be used to check if a specific value match to an expected one.\" \/>\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-assertthat-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JUnit AssertThat Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"1. Introduction The assertThat is one of the JUnit methods from the Assert object that can be used to check if a specific value match to an expected one.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-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:author\" content=\"https:\/\/www.facebook.com\/alvinjayreyes\" \/>\n<meta property=\"article:published_time\" content=\"2015-07-17T08:00:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-21T10:34:12+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=\"Alvin Reyes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@alvinjayreyes\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alvin Reyes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 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-assertthat-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/\"},\"author\":{\"name\":\"Alvin Reyes\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/b5bc005030b168a0a95f041b047bf82d\"},\"headline\":\"JUnit AssertThat Example\",\"datePublished\":\"2015-07-17T08:00:33+00:00\",\"dateModified\":\"2019-03-21T10:34:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/\"},\"wordCount\":425,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"articleSection\":[\"junit\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/\",\"name\":\"JUnit AssertThat Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"datePublished\":\"2015-07-17T08:00:33+00:00\",\"dateModified\":\"2019-03-21T10:34:12+00:00\",\"description\":\"1. Introduction The assertThat is one of the JUnit methods from the Assert object that can be used to check if a specific value match to an expected one.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-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-assertthat-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 AssertThat 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\/b5bc005030b168a0a95f041b047bf82d\",\"name\":\"Alvin Reyes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/01\/Alvin-Reyes-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/01\/Alvin-Reyes-96x96.jpg\",\"caption\":\"Alvin Reyes\"},\"description\":\"Alvin has an Information Technology Degree from Mapua Institute of Technology. During his studies, he was already heavily involved in a number of small to large projects where he primarily contributes by doing programming, analysis design. After graduating, he continued to do side projects on Mobile, Desktop and Web Applications.\",\"sameAs\":[\"http:\/\/www.alvinjayreyes.com\",\"https:\/\/www.facebook.com\/alvinjayreyes\",\"http:\/\/ca.linkedin.com\/in\/alvinpreyes\",\"https:\/\/x.com\/alvinjayreyes\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/alvin-reyes\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JUnit AssertThat Example - Java Code Geeks","description":"1. Introduction The assertThat is one of the JUnit methods from the Assert object that can be used to check if a specific value match to an expected one.","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-assertthat-example\/","og_locale":"en_US","og_type":"article","og_title":"JUnit AssertThat Example - Java Code Geeks","og_description":"1. Introduction The assertThat is one of the JUnit methods from the Assert object that can be used to check if a specific value match to an expected one.","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/alvinjayreyes","article_published_time":"2015-07-17T08:00:33+00:00","article_modified_time":"2019-03-21T10:34:12+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":"Alvin Reyes","twitter_card":"summary_large_image","twitter_creator":"@alvinjayreyes","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Alvin Reyes","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/"},"author":{"name":"Alvin Reyes","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/b5bc005030b168a0a95f041b047bf82d"},"headline":"JUnit AssertThat Example","datePublished":"2015-07-17T08:00:33+00:00","dateModified":"2019-03-21T10:34:12+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/"},"wordCount":425,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","articleSection":["junit"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/","name":"JUnit AssertThat Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","datePublished":"2015-07-17T08:00:33+00:00","dateModified":"2019-03-21T10:34:12+00:00","description":"1. Introduction The assertThat is one of the JUnit methods from the Assert object that can be used to check if a specific value match to an expected one.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-assertthat-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-assertthat-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 AssertThat 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\/b5bc005030b168a0a95f041b047bf82d","name":"Alvin Reyes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/01\/Alvin-Reyes-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/01\/Alvin-Reyes-96x96.jpg","caption":"Alvin Reyes"},"description":"Alvin has an Information Technology Degree from Mapua Institute of Technology. During his studies, he was already heavily involved in a number of small to large projects where he primarily contributes by doing programming, analysis design. After graduating, he continued to do side projects on Mobile, Desktop and Web Applications.","sameAs":["http:\/\/www.alvinjayreyes.com","https:\/\/www.facebook.com\/alvinjayreyes","http:\/\/ca.linkedin.com\/in\/alvinpreyes","https:\/\/x.com\/alvinjayreyes"],"url":"https:\/\/examples.javacodegeeks.com\/author\/alvin-reyes\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/25195","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\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=25195"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/25195\/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=25195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=25195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=25195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}