{"id":39633,"date":"2016-08-03T15:00:15","date_gmt":"2016-08-03T12:00:15","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=39633"},"modified":"2019-04-09T13:29:54","modified_gmt":"2019-04-09T10:29:54","slug":"mockito-test-case-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/","title":{"rendered":"Mockito Test Case Example"},"content":{"rendered":"<p>A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write beautiful tests with a clean &amp; simple API. In this example we will learn how to write a simple test case using Mockito. Tools and technologies used in this example are Java 1.8, Eclipse Luna 4.4.2<\/p>\n<h2>1. Introduction<\/h2>\n<p>Mockito is a popular mocking framework which can be used in conjunction with JUnit. Mockito allows us to create and configure mock objects. Using Mockito simplifies the development of tests for classes with external dependencies significantly.&nbsp;We can create the mock objects manually or we can use the mocking framewors like Mockito, EasyMock. jMock etc.&nbsp;Mock frameworks allow us to create mock objects at runtime and define their behavior.&nbsp;The classical example for a mock object is a data provider. In production, a real database is used, but for testing a mock object simulates the database and ensures that the test conditions are always the same.\n<\/p>\n<h2>2. Creating a project<\/h2>\n<p>Below are the steps required to create the project.<\/p>\n<ul>\n<li>Open Eclipse. Go to File=&gt;New=&gt;Java Project. In the \u2018Project name\u2019 enter \u2018MockitoExample\u2019.<\/li>\n<\/ul>\n<p><figure id=\"attachment_39637\" aria-describedby=\"caption-attachment-39637\" style=\"width: 519px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/Create-Java-Project-2.jpg\"><img decoding=\"async\" class=\"size-full wp-image-39637\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/Create-Java-Project-2.jpg\" alt=\"Figure 1. Create Java Project\" width=\"519\" height=\"710\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/Create-Java-Project-2.jpg 519w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/Create-Java-Project-2-219x300.jpg 219w\" sizes=\"(max-width: 519px) 100vw, 519px\" \/><\/a><figcaption id=\"caption-attachment-39637\" class=\"wp-caption-text\">Figure 1. Create Java Project<\/figcaption><\/figure><\/p>\n<ul>\n<li>Eclipse will create a \u2018src\u2019 folder. Right click on the \u2018src\u2019 folder and choose New=&gt;Package. In the \u2018Name\u2019 text-box enter \u2018com.javacodegeeks\u2019. Click \u2018Finish\u2019.<\/li>\n<\/ul>\n<p><figure id=\"attachment_39638\" aria-describedby=\"caption-attachment-39638\" style=\"width: 511px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/Java-Package-1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-39638\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/Java-Package-1.jpg\" alt=\"Figure 2. Java Project\" width=\"511\" height=\"494\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/Java-Package-1.jpg 511w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/Java-Package-1-300x290.jpg 300w\" sizes=\"(max-width: 511px) 100vw, 511px\" \/><\/a><figcaption id=\"caption-attachment-39638\" class=\"wp-caption-text\">Figure 2. Java Project<\/figcaption><\/figure><\/p>\n<ul>\n<li>Right click on the package and choose New=&gt;Class. Give the class name and click \u2018Finish\u2019. Eclipse will create a default class with the given name.<\/li>\n<\/ul>\n<h3>3.1 Declaring mockito dependency<\/h3>\n<p>For this example we need the junit and mockito jars. These jars can be downloaded from <a href=\"http:\/\/search.maven.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">Maven repository<\/a>. We are using \u2018junit-4.12.jar\u2019 and \u2018mockito-all-1.10.19.jar\u2019. There are the latests versions available as per now. To add these jars in the classpath right click on the project and choose Build Path=&gt;Configure Build Path. The click on the \u2018Add External JARs\u2019 button on the right hand side. Then go to the location where you have downloaded these jars. Then click ok.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>If you are using Gradle you&nbsp;can do:<\/p>\n<p>repositories { jcenter() }<br \/>\ndependencies { testCompile &#8220;org.mockito:mockito-core:1.+&#8221; }<\/p>\n<h2>4. Code<\/h2>\n<p>In this section we will see some simple code examples.<\/p>\n<h3>4.1 Mock<\/h3>\n<p>To mock the class we make use of the <code>mock()<\/code> method of the <code>Mockito<\/code> class. It creates a mock object of a given class or interface:<\/p>\n<pre class=\"brush:java\">public static &lt;T&gt; T mock(Class&lt;T&gt; classToMock)\n<\/pre>\n<p>Below is the code snippet we use to mock:<\/p>\n<pre class=\"brush:java\">\/\/ Create Mock\nStack&lt;String&gt; mockStack = Mockito.mock(Stack.class);\n<\/pre>\n<p>Mockito also supports the creation of mock objects based on the <code>@Mock<\/code> annotation. You annotate the class with <code>@Mock<\/code> as below:<\/p>\n<pre class=\"brush:java\">@Mock private IReportGenerator reportGenerator;\n<\/pre>\n<p>Then you annotate the class (which you want to test) which has the reference to this mocked class with&nbsp;<code>@InjectMocks<\/code>:<\/p>\n<pre class=\"brush:java\">@InjectMocks private ReportGeneratorService reportGeneratorService;\n<\/pre>\n<p>After this you need to initialize the mocks. We can do this by calling the&nbsp;<code>initMocks()<\/code> method of&nbsp;<code>MockitoAnnotations<\/code> class.<\/p>\n<pre class=\"brush:java\">@Before\npublic void setUp() {\nMockitoAnnotations.initMocks(this);\n}<\/pre>\n<h3>4.2 Verify<\/h3>\n<p>Let us see the usage of <code>verify()<\/code> method of Mockito class. This verifies that certain behavior happened once. You can also use another overloaded method which takes an extra integer argument (<code>times(int)<\/code>). The arguments passed are compared using <code>equals()<\/code> method. Let&#8217;s see an example now.<\/p>\n<pre class=\"brush:java\">\/\/ Create Mock\nStack&lt;String&gt; mockStack = Mockito.mock(Stack.class);\n\/\/ Use mock object\nmockStack.add(\"Test verify\");\nMockito.verify(mockStack).add(\"Test verify\");\n<\/pre>\n<h3>4.3 Stub<\/h3>\n<p>In this section we will see how we can stub a method call. To stub a method we will make use of the <code>when()<\/code> method.&nbsp;Stubbing can be overridden: For example common stubbing can go to fixture&nbsp;setup but the test methods can override it.&nbsp;Please note that overridding stubbing is a potential code smell that points out too much stubbing.&nbsp;Once stubbed, the method will always return stubbed value regardless&nbsp;of how many times it is called.&nbsp;Last stubbing is more important &#8211; when you stubbed the same method with&nbsp;the same arguments many times.&nbsp;Although it is possible to verify a stubbed invocation, usually it&#8217;s just redundant.[ulp id=&#8217;GhnY46zldrhgoeym&#8217;]<\/p>\n<p>By default, for all methods that return a value, a mock will return either null, a primitive\/primitive wrapper value, or an empty collection, as appropriate. For example 0 for an int\/Integer and false for a boolean\/Boolean.<\/p>\n<p>The other method we use for stubbing is <code>thenReturn()<\/code>. It sets a return value to be returned when the method is called. See the code snippet below:<\/p>\n<pre class=\"brush:java\">\/\/ Create Mock\nStack&lt;String&gt; mockStack = Mockito.mock(Stack.class);\nAssert.assertEquals(mockStack.capacity(), 0);\n\/\/ Stub\nMockito.when(mockStack.capacity()).thenReturn(10);\nAssert.assertEquals(mockStack.capacity(), 10);\nMockito.verify(mockStack);\n<\/pre>\n<h3>4.4 Argument matchers<\/h3>\n<p>Mockito verifies argument values in natural java style: by using an <code>equals()<\/code> method. Sometimes, when extra flexibility is required then you might use argument matchers:<\/p>\n<pre class=\"brush:java\">Stack&lt;String&gt; mockStack = Mockito.mock(Stack.class);\nMockito.when(mockStack.get(Mockito.anyInt())).thenReturn(\"PASS\");\nAssert.assertEquals(mockStack.get(0), \"PASS\");\nAssert.assertEquals(mockStack.get(10), \"PASS\");\nMockito.verify(mockStack, Mockito.times(2)).get(Mockito.anyInt());\n<\/pre>\n<p>Argument matchers allow flexible verification or stubbing.&nbsp;Be reasonable with using complicated argument matching. The natural matching style using <code>equals()<\/code> with occasional <code>anyX()<\/code> matchers tend to give clean &amp; simple tests. Sometimes it&#8217;s just better to refactor the code to allow <code>equals()<\/code> matching or even implement <code>equals()<\/code> method to help out with testing.&nbsp;If you are using argument matchers, all arguments have to be provided by matchers.<\/p>\n<h3>4.5 Stub void method<\/h3>\n<p>In this section we will see how we can stub void methods with exception. We will make use of the <code>doThrow()<\/code> method of the Mockito class<\/p>\n<pre class=\"brush:java\">mock = Mockito.mock(VoidMethodClass.class);\nMockito.doThrow(new IllegalArgumentException()).when(mock).voidMethodThrowingExcetion(false);\nmock.voidMethodThrowingExcetion(true);\nMockito.doThrow(new IllegalArgumentException()).when(mock).voidMethodThrowingExcetion(true);\ntry {\n  mock.voidMethodThrowingExcetion(true);\n  Assert.fail();\n} catch (IllegalArgumentException e) {\n}<\/pre>\n<h2>5. Download the source file<\/h2>\n<p>This was a very simple example of using Mockito to write unit tests. There are lots of other features which Mockito provides. You can look at the Mockito website for more details.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <strong><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/08\/MockitoExample.zip\">MockitoExample<\/a><\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write beautiful tests with a clean &amp; simple API. In this example we will learn how to write a simple test case using Mockito. Tools and technologies used in this &hellip;<\/p>\n","protected":false},"author":34,"featured_media":21338,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[923],"tags":[1032,918],"class_list":["post-39633","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>Mockito Test Case Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write\" \/>\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\/mockito-test-case-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Mockito Test Case Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-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=\"2016-08-03T12:00:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-09T10:29:54+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=\"Mohammad Meraj Zia\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mohammad Meraj Zia\" \/>\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\/mockito-test-case-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/\"},\"author\":{\"name\":\"Mohammad Meraj Zia\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/442b4f9b8a4aa7e12376464fc354f8ed\"},\"headline\":\"Mockito Test Case Example\",\"datePublished\":\"2016-08-03T12:00:15+00:00\",\"dateModified\":\"2019-04-09T10:29:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/\"},\"wordCount\":880,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-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\/mockito-test-case-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/\",\"name\":\"Mockito Test Case Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/mockito-logo.jpg\",\"datePublished\":\"2016-08-03T12:00:15+00:00\",\"dateModified\":\"2019-04-09T10:29:54+00:00\",\"description\":\"A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-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\/mockito-test-case-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\":\"Mockito Test Case 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\/442b4f9b8a4aa7e12376464fc354f8ed\",\"name\":\"Mohammad Meraj Zia\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/IMG-20200324-WA0003-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/IMG-20200324-WA0003-96x96.jpg\",\"caption\":\"Mohammad Meraj Zia\"},\"description\":\"Senior Java Developer\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/mohammad-zia\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Mockito Test Case Example - Java Code Geeks","description":"A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write","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\/mockito-test-case-example\/","og_locale":"en_US","og_type":"article","og_title":"Mockito Test Case Example - Java Code Geeks","og_description":"A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2016-08-03T12:00:15+00:00","article_modified_time":"2019-04-09T10:29:54+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":"Mohammad Meraj Zia","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Mohammad Meraj Zia","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/"},"author":{"name":"Mohammad Meraj Zia","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/442b4f9b8a4aa7e12376464fc354f8ed"},"headline":"Mockito Test Case Example","datePublished":"2016-08-03T12:00:15+00:00","dateModified":"2019-04-09T10:29:54+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/"},"wordCount":880,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-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\/mockito-test-case-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/","name":"Mockito Test Case Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/mockito-logo.jpg","datePublished":"2016-08-03T12:00:15+00:00","dateModified":"2019-04-09T10:29:54+00:00","description":"A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/mockito\/mockito-test-case-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\/mockito-test-case-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":"Mockito Test Case 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\/442b4f9b8a4aa7e12376464fc354f8ed","name":"Mohammad Meraj Zia","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/IMG-20200324-WA0003-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/IMG-20200324-WA0003-96x96.jpg","caption":"Mohammad Meraj Zia"},"description":"Senior Java Developer","sameAs":["http:\/\/www.javacodegeeks.com\/"],"url":"https:\/\/examples.javacodegeeks.com\/author\/mohammad-zia\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/39633","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\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=39633"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/39633\/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=39633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=39633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=39633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}