{"id":3044,"date":"2011-02-19T16:15:13","date_gmt":"2011-02-19T15:15:13","guid":{"rendered":"http:\/\/blog.jteam.nl\/?p=3044"},"modified":"2011-02-19T16:15:13","modified_gmt":"2011-02-19T15:15:13","slug":"some-trouble-with-getting-the-right-version-of-hamcrest-and-the-solution","status":"publish","type":"post","link":"https:\/\/trifork.nl\/blog\/some-trouble-with-getting-the-right-version-of-hamcrest-and-the-solution\/","title":{"rendered":"Using Hamcrest Matchers.everyItem"},"content":{"rendered":"<p>For my Junit test I wanted to make use of Matchers.everyItem so I could easily check if every item of a list machtes a certain matcher. Resulting in a small line of code which is nice to read.<\/p>\n<p><!--more-->The code:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\nassertThat(itemResults, everyItem(Matchers.&lt;ItemResult&gt;hasProperty(&quot;score&quot;, is(new Double(1.0)))));\n<\/pre>\n<p>The <strong>everyItem<\/strong> machter is available in hamcrest 1.2 so an easy update would do the trick. And of course it doesn&#8217;t. The project had a dependency on hamcrest-all 1.1. Unfortunately there is no 1.2 version. After some searching I could use the hamcrest-integration 1.2.1 (which depends on core and library).<\/p>\n<p>This upgrade resulted in a few compile errors. For example:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\nhasItems(is(ownerId1), is(ownerId2)));\n\/\/ should be:\nMatchers.&lt;String&gt;hasItems(is(ownerId1), is(ownerId2)));\n\n\/\/ and\nassertThat(object, is(ArrayList.class));\n\/\/ should be:\nassertThat(object, Matchers.&lt;Object&gt;instanceOf(ArrayList.class));\n<\/pre>\n<p>When running the test I&#8217;ve got a <strong>NoSuchMethodException<\/strong>. Which is cause by conflicting classes in the Junit 4.8.2 jar. For some reason they added Hamcrest classes version 1.1 to the jar.<\/p>\n<p>This can be fixed by using artifactId junit-dep instead of junit and add an exclusion to prevent maven to fetch the 1.1 version of the hamcrest-core. (See the maven snippet below.)<\/p>\n<p>Enjoy using junit and hamcrest!<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;dependencies&gt;\n  &lt;dependency&gt;\n    &lt;groupId&gt;junit&lt;\/groupId&gt;\n    &lt;artifactId&gt;junit-dep&lt;\/artifactId&gt;\n    &lt;version&gt;4.8.2&lt;\/version&gt;\n    &lt;scope&gt;test&lt;\/scope&gt;\n    &lt;exclusions&gt;\n      &lt;exclusion&gt;\n        &lt;groupId&gt;org.hamcrest&lt;\/groupId&gt;\n        &lt;artifactId&gt;hamcrest-core&lt;\/artifactId&gt;\n      &lt;\/exclusion&gt;\n    &lt;\/exclusions&gt;\n  &lt;\/dependency&gt;\n  &lt;dependency&gt;\n    &lt;groupId&gt;org.hamcrest&lt;\/groupId&gt;\n    &lt;artifactId&gt;hamcrest-integration&lt;\/artifactId&gt;\n    &lt;version&gt;1.2.1&lt;\/version&gt;\n    &lt;scope&gt;test&lt;\/scope&gt;\n  &lt;\/dependency&gt;\n&lt;\/dependencies&gt;\n<\/pre>\n<div id=\"_mcePaste\" style=\"position: absolute;left: -10000px;top: 114px;width: 1px;height: 1px;overflow: hidden\">\n<p>[\/code]<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>For my Junit test I wanted to make use of Matchers.everyItem so I could easily check if every item of a list machtes a certain matcher. Resulting in a small line of code which is nice to read.<\/p>\n","protected":false},"author":78,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[31],"tags":[229,143,102],"class_list":["post-3044","post","type-post","status-publish","format-standard","hentry","category-java","tag-hamcrest","tag-junit","tag-maven"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using Hamcrest Matchers.everyItem - Trifork Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/trifork.nl\/blog\/some-trouble-with-getting-the-right-version-of-hamcrest-and-the-solution\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using Hamcrest Matchers.everyItem - Trifork Blog\" \/>\n<meta property=\"og:description\" content=\"For my Junit test I wanted to make use of Matchers.everyItem so I could easily check if every item of a list machtes a certain matcher. Resulting in a small line of code which is nice to read.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/trifork.nl\/blog\/some-trouble-with-getting-the-right-version-of-hamcrest-and-the-solution\/\" \/>\n<meta property=\"og:site_name\" content=\"Trifork Blog\" \/>\n<meta property=\"article:published_time\" content=\"2011-02-19T15:15:13+00:00\" \/>\n<meta name=\"author\" content=\"Martin Tilma\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Martin Tilma\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/trifork.nl\/blog\/some-trouble-with-getting-the-right-version-of-hamcrest-and-the-solution\/\",\"url\":\"https:\/\/trifork.nl\/blog\/some-trouble-with-getting-the-right-version-of-hamcrest-and-the-solution\/\",\"name\":\"Using Hamcrest Matchers.everyItem - Trifork Blog\",\"isPartOf\":{\"@id\":\"https:\/\/trifork.nl\/blog\/#website\"},\"datePublished\":\"2011-02-19T15:15:13+00:00\",\"author\":{\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/8b8a3958adbd9f58d1c257c622fe0f4e\"},\"breadcrumb\":{\"@id\":\"https:\/\/trifork.nl\/blog\/some-trouble-with-getting-the-right-version-of-hamcrest-and-the-solution\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/trifork.nl\/blog\/some-trouble-with-getting-the-right-version-of-hamcrest-and-the-solution\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/trifork.nl\/blog\/some-trouble-with-getting-the-right-version-of-hamcrest-and-the-solution\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/trifork.nl\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using Hamcrest Matchers.everyItem\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/trifork.nl\/blog\/#website\",\"url\":\"https:\/\/trifork.nl\/blog\/\",\"name\":\"Trifork Blog\",\"description\":\"Keep updated on the technical solutions Trifork is working on!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/trifork.nl\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/8b8a3958adbd9f58d1c257c622fe0f4e\",\"name\":\"Martin Tilma\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b4ccfbaec8216c8fa31c753299573cae?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b4ccfbaec8216c8fa31c753299573cae?s=96&d=mm&r=g\",\"caption\":\"Martin Tilma\"},\"url\":\"https:\/\/trifork.nl\/blog\/author\/martin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using Hamcrest Matchers.everyItem - Trifork Blog","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:\/\/trifork.nl\/blog\/some-trouble-with-getting-the-right-version-of-hamcrest-and-the-solution\/","og_locale":"en_US","og_type":"article","og_title":"Using Hamcrest Matchers.everyItem - Trifork Blog","og_description":"For my Junit test I wanted to make use of Matchers.everyItem so I could easily check if every item of a list machtes a certain matcher. Resulting in a small line of code which is nice to read.","og_url":"https:\/\/trifork.nl\/blog\/some-trouble-with-getting-the-right-version-of-hamcrest-and-the-solution\/","og_site_name":"Trifork Blog","article_published_time":"2011-02-19T15:15:13+00:00","author":"Martin Tilma","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Martin Tilma","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/trifork.nl\/blog\/some-trouble-with-getting-the-right-version-of-hamcrest-and-the-solution\/","url":"https:\/\/trifork.nl\/blog\/some-trouble-with-getting-the-right-version-of-hamcrest-and-the-solution\/","name":"Using Hamcrest Matchers.everyItem - Trifork Blog","isPartOf":{"@id":"https:\/\/trifork.nl\/blog\/#website"},"datePublished":"2011-02-19T15:15:13+00:00","author":{"@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/8b8a3958adbd9f58d1c257c622fe0f4e"},"breadcrumb":{"@id":"https:\/\/trifork.nl\/blog\/some-trouble-with-getting-the-right-version-of-hamcrest-and-the-solution\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/trifork.nl\/blog\/some-trouble-with-getting-the-right-version-of-hamcrest-and-the-solution\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/trifork.nl\/blog\/some-trouble-with-getting-the-right-version-of-hamcrest-and-the-solution\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/trifork.nl\/blog\/"},{"@type":"ListItem","position":2,"name":"Using Hamcrest Matchers.everyItem"}]},{"@type":"WebSite","@id":"https:\/\/trifork.nl\/blog\/#website","url":"https:\/\/trifork.nl\/blog\/","name":"Trifork Blog","description":"Keep updated on the technical solutions Trifork is working on!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/trifork.nl\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/8b8a3958adbd9f58d1c257c622fe0f4e","name":"Martin Tilma","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b4ccfbaec8216c8fa31c753299573cae?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b4ccfbaec8216c8fa31c753299573cae?s=96&d=mm&r=g","caption":"Martin Tilma"},"url":"https:\/\/trifork.nl\/blog\/author\/martin\/"}]}},"_links":{"self":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts\/3044","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/users\/78"}],"replies":[{"embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/comments?post=3044"}],"version-history":[{"count":0,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts\/3044\/revisions"}],"wp:attachment":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/media?parent=3044"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/categories?post=3044"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/tags?post=3044"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}