{"id":26964,"date":"2015-09-14T15:00:40","date_gmt":"2015-09-14T12:00:40","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=26964"},"modified":"2019-04-09T13:35:08","modified_gmt":"2019-04-09T10:35:08","slug":"junit-mockito-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/","title":{"rendered":"JUnit Mockito Example"},"content":{"rendered":"<h2>1. Introduction<\/h2>\n<p>Methods and ways to create Unit Test cases have evolve ever since it&#8217;s introduction. New tools and API\u00b4s are now available and they provide a more advanced scheme on creating and executing JUnit Test cases. Services have become more incubated, so creating integration test cases has been a daunting task for any developer.<\/p>\n<p>The introduction of this new development approach made revolutionary changes in Unit testing as well and a lot of testing framework came and rise the level at the playing field. With this, the need to create mocking objects to mimic Java objects in their runtime has never been more important, especially on critical enterprise software.<\/p>\n<p>In this post, I&#8217;ll be showing one of the most widely used and popular JUnit Testing Mocking framework &#8211; <a href=\"http:\/\/mockito.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">Mockito<\/a>.\n<\/p>\n<h2>2. Mockito Framework<\/h2>\n<p>Mockito is one of the widely used testing API for Java. Tons of examples are accepted by the massive Java community. Back in 2008, Dan North said that this was the future model of testing java applications. The popularity of Mockito and the overall Java projects in Github that use this API, clearly state that the prediction was true.<\/p>\n<h2>3. Eclipse Example<\/h2>\n<p>Let&#8217;s take a deep dive into an example. In this example we&#8217;ll create the following:<\/p>\n<ul>\n<li>Create a new Maven Project<\/li>\n<li>Define the dependencies we need. That is JUnit and Mockito<\/li>\n<li>Code some examples<\/li>\n<\/ul>\n<h3>3.1 Maven Project<\/h3>\n<p>Let&#8217;s first create a new Maven project. In your eclipse click on File &gt; New Project &gt; Maven Project. Tick on create a simple project fill up the group id, artefact id and hit Finish.<\/p>\n<p><figure id=\"attachment_27175\" aria-describedby=\"caption-attachment-27175\" style=\"width: 1003px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/new_maven_project.jpg\"><img decoding=\"async\" class=\"size-full wp-image-27175\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/new_maven_project.jpg\" alt=\"Figure 1.0 Maven project\" width=\"1003\" height=\"538\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/new_maven_project.jpg 1003w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/new_maven_project-300x160.jpg 300w\" sizes=\"(max-width: 1003px) 100vw, 1003px\" \/><\/a><figcaption id=\"caption-attachment-27175\" class=\"wp-caption-text\">Figure 1.0 Maven project<\/figcaption><\/figure><\/p>\n<h3>3.2 pom.xml configuration<\/h3>\n<p>We then include the dependencies we need. This will download the libraries for our project.<\/p>\n<p><span style=\"text-decoration: underline\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n\txsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&gt;\n\t&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\n\t&lt;groupId&gt;com.jgc.areyes.junit&lt;\/groupId&gt;\n\t&lt;artifactId&gt;junit-mockito-example&lt;\/artifactId&gt;\n\t&lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\n\n\t&lt;dependencies&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;junit&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;junit&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;4.12&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;org.mockito&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;mockito-all&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;1.9.5&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\t&lt;\/dependencies&gt;\n&lt;\/project&gt;\n<\/pre>\n<h3>3.3 Test Case Example<\/h3>\n<p><span style=\"text-decoration: underline\"><em>JUnitServiceTestExample.java<\/em><\/span><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:java\">package com.areyes1.jgc.mockito.e;\n\nimport static org.mockito.Mockito.*;\nimport static org.junit.Assert.*;\n\nimport java.util.Iterator;\n\nimport org.junit.Test;\nimport org.mockito.Matchers;\nimport org.mockito.Mockito;\n\n\/**\n * The Class JUnitServiceTestExample.\n *\/\npublic class JUnitServiceTestExample {\n\n\t\/**\n\t * Test1.\n\t *\/\n\t@Test\n\tpublic void testSimpleInt() {\n\t\t\/\/ create mock\n\t\tTestService test = Mockito.mock(TestService.class);\n\n\t\t\/\/ define return value for method getUniqueId()\n\t\twhen(test.getUniqueId()).thenReturn(43);\n\n\t\t\/\/ use mock in test....\n\t\tassertEquals(test.getUniqueId(), 43);\n\t}\n\n\t\/**\n\t * Test more than one return value.\n\t *\/\n\t\/\/ Demonstrates the return of multiple values\n\t@Test\n\tpublic void testMoreThanOneReturnValue() {\n\t\tIterator i = mock(Iterator.class);\n\t\twhen(i.next()).thenReturn(\"Mockito\").thenReturn(\"is neat!!\");\n\t\tString result = i.next() + \" \" + i.next();\n\t\tassertEquals(\"Mockito is neat!!\", result);\n\t}\n\n\t\/**\n\t * Test return value dependent on method parameter.\n\t *\/\n\t@Test\n\tpublic void testReturnValueDependentOnMethodParameter() {\n\t\tComparable c = mock(Comparable.class);\n\t\twhen(c.compareTo(\"Mockito\")).thenReturn(1);\n\t\twhen(c.compareTo(\"Eclipse\")).thenReturn(2);\n\t\t\/\/ assert\n\t\tassertEquals(1, c.compareTo(\"Mockito\"));\n\t}\n\n\t\/**\n\t * Test return value in dependent on method parameter.\n\t *\/\n\t@Test\n\tpublic void testReturnValueInDependentOnMethodParameter() {\n\t\tComparable c = mock(Comparable.class);\n\t\twhen(c.compareTo(anyInt())).thenReturn(-1);\n\t\tassertEquals(-1, c.compareTo(9));\n\t}\n\n\t@Test\n\tpublic void testVerify() {\n\t\t\/\/ create and configure mock\n\t\tTestService test = Mockito.mock(TestService.class);\n\t\twhen(test.getUniqueId()).thenReturn(43);\n\n\t\t\/\/ call method testing on the mock with parameter 12\n\t\ttest.testing(12);\n\t\ttest.getUniqueId();\n\t\ttest.getUniqueId();\n\t\ttest.someMethod(\"Hello World\");\n\t\ttest.someMethod(\"called at least once\");\n\t\ttest.someMethod(\"called at least twice\");\n\t\ttest.someMethod(\"called five times\");\n\t\ttest.someMethod(\"called at most 3 times\");\n\n\t\t\/\/ now check if method testing was called with the parameter 12\n\t\tverify(test).testing(Matchers.eq(12));\n\n\t\t\/\/ was the method called twice?\n\t\tverify(test, times(2)).getUniqueId();\n\n\t\t\/\/ other alternatives for verifiying the number of method calls for a\n\t\t\/\/ method\n\t\tverify(test, never()).someMethod(\"never called\");\n\t\tverify(test, atLeastOnce()).someMethod(\"called at least once\");\n\t\t\n\t\t\/\/\tWill all fail because we didn't met the conditions.\n\t\tverify(test, atLeast(2)).someMethod(\"called at least twice\");\t \n\t\tverify(test, times(5)).someMethod(\"called five times\");\n\t\tverify(test, atMost(3)).someMethod(\"called at most 3 times\");\n\t}\n\n}\n<\/pre>\n<p>The example above showcases the different unique usage of <a href=\"http:\/\/mockito.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">Mockito<\/a>. Aside from just mocking objects, it also perfectly compliments what we call &#8220;behaviour driven&#8221; test cases. This means that the test case is aimed at testing the behaviour or any method calls within the services aside from the output itself.[ulp id=&#8217;GhnY46zldrhgoeym&#8217;]<\/p>\n<p>Let&#8217;s go over each method:<\/p>\n<ul>\n<li><code>testSimpleInt<\/code> &#8211; the test case creates a mock class and calls the method. It enforces the method to use 43 as it&#8217;s return. This is then tested via an <code><a href=\"http:\/\/junit.sourceforge.net\/javadoc\/org\/junit\/Assert.html\" target=\"_blank\" rel=\"noopener noreferrer\">assertEquals<\/a><\/code> method as shown.<\/li>\n<li><code>testMoreThanOneReturnValue<\/code> &#8211; the cases mocked an iterator class and sets a new value for the first record. The example shown concatenates two new strings on the 1st element. This record is then tested via an <code><a href=\"http:\/\/junit.sourceforge.net\/javadoc\/org\/junit\/Assert.html\" target=\"_blank\" rel=\"noopener noreferrer\">assertEquals<\/a><\/code> method.<\/li>\n<li><code>testReturnValueInDependentOnMethodParameter<\/code> &#8211; The test case shows how we can dynamically use other results even in our comparison logic. In this example, we forced the comparisons to return values that are then tested via an <code><a href=\"http:\/\/junit.sourceforge.net\/javadoc\/org\/junit\/Assert.html\" target=\"_blank\" rel=\"noopener noreferrer\">assertEquals<\/a><\/code> method.<\/li>\n<li><code>testVerify<\/code> &#8211; the test case showcases how we can test the behaviour of a method within the class. It tests how many calls were made to the method and if there are any changes to the return types. This is a powerful feature because not only allows developers to test results, but also the behaviour of a specific service can be tested.<\/li>\n<\/ul>\n<p>Mockito has redefined the creation of test cases. Almost every project globally uses the API. It\u00b4s not just about mocking objects and classes but its also that it has created a venue for developers to develop more concrete, bulletproof test cases that ensure the stability of the software.<\/p>\n<h2>4 Output<\/h2>\n<p>Running the test case above will give the output below.<\/p>\n<p><figure id=\"attachment_27181\" aria-describedby=\"caption-attachment-27181\" style=\"width: 596px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/output_mockito.jpg\"><img decoding=\"async\" class=\"size-full wp-image-27181\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/output_mockito.jpg\" alt=\"Figure 2.0 Mockito test cases output\" width=\"596\" height=\"343\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/output_mockito.jpg 596w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/output_mockito-300x173.jpg 300w\" sizes=\"(max-width: 596px) 100vw, 596px\" \/><\/a><figcaption id=\"caption-attachment-27181\" class=\"wp-caption-text\">Figure 2.0 Mockito test cases output<\/figcaption><\/figure><\/p>\n<h2>5. Download the Eclipse project<\/h2>\n<p>This was an example of JUnit Mockito.<\/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\/09\/junit-mockito-example.zip\"><strong>junit-mockito-example<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction Methods and ways to create Unit Test cases have evolve ever since it&#8217;s introduction. New tools and API\u00b4s are now available and they provide a more advanced scheme on creating and executing JUnit Test cases. Services have become more incubated, so creating integration test cases has been a daunting task for any developer. &hellip;<\/p>\n","protected":false},"author":41,"featured_media":21338,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[923],"tags":[1032,918],"class_list":["post-26964","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mockito","tag-junit","tag-mockito"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JUnit Mockito Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"1. Introduction Methods and ways to create Unit Test cases have evolve ever since it&#039;s introduction. New tools and API\u00b4s are now available and they\" \/>\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\/mockito\/junit-mockito-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JUnit Mockito Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"1. Introduction Methods and ways to create Unit Test cases have evolve ever since it&#039;s introduction. New tools and API\u00b4s are now available and they\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-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-09-14T12:00:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-09T10:35:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/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=\"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=\"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\/mockito\/junit-mockito-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/\"},\"author\":{\"name\":\"Alvin Reyes\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/b5bc005030b168a0a95f041b047bf82d\"},\"headline\":\"JUnit Mockito Example\",\"datePublished\":\"2015-09-14T12:00:40+00:00\",\"dateModified\":\"2019-04-09T10:35:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/\"},\"wordCount\":622,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/mockito-logo.jpg\",\"keywords\":[\"junit\",\"mockito\"],\"articleSection\":[\"Mockito\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/\",\"name\":\"JUnit Mockito Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/mockito-logo.jpg\",\"datePublished\":\"2015-09-14T12:00:40+00:00\",\"dateModified\":\"2019-04-09T10:35:08+00:00\",\"description\":\"1. Introduction Methods and ways to create Unit Test cases have evolve ever since it's introduction. New tools and API\u00b4s are now available and they\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/mockito-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/mockito-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-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\":\"Mockito\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/mockito\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"JUnit Mockito 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 Mockito Example - Java Code Geeks","description":"1. Introduction Methods and ways to create Unit Test cases have evolve ever since it's introduction. New tools and API\u00b4s are now available and they","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\/mockito\/junit-mockito-example\/","og_locale":"en_US","og_type":"article","og_title":"JUnit Mockito Example - Java Code Geeks","og_description":"1. Introduction Methods and ways to create Unit Test cases have evolve ever since it's introduction. New tools and API\u00b4s are now available and they","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-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-09-14T12:00:40+00:00","article_modified_time":"2019-04-09T10:35:08+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/mockito-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":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/"},"author":{"name":"Alvin Reyes","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/b5bc005030b168a0a95f041b047bf82d"},"headline":"JUnit Mockito Example","datePublished":"2015-09-14T12:00:40+00:00","dateModified":"2019-04-09T10:35:08+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/"},"wordCount":622,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/mockito-logo.jpg","keywords":["junit","mockito"],"articleSection":["Mockito"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/","name":"JUnit Mockito Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/mockito-logo.jpg","datePublished":"2015-09-14T12:00:40+00:00","dateModified":"2019-04-09T10:35:08+00:00","description":"1. Introduction Methods and ways to create Unit Test cases have evolve ever since it's introduction. New tools and API\u00b4s are now available and they","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/mockito-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/mockito-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/junit-mockito-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":"Mockito","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/mockito\/"},{"@type":"ListItem","position":5,"name":"JUnit Mockito 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\/26964","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=26964"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/26964\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/21338"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=26964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=26964"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=26964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}