{"id":44892,"date":"2015-11-15T15:24:33","date_gmt":"2015-11-15T13:24:33","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=44892"},"modified":"2023-12-13T11:08:56","modified_gmt":"2023-12-13T09:08:56","slug":"mockito-verification","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html","title":{"rendered":"Mockito Verification"},"content":{"rendered":"<p><em>This article is part of our Academy Course titled <a href=\"http:\/\/www.javacodegeeks.com\/2015\/09\/testing-with-mockito\/\">Testing with Mockito<\/a>.<\/p>\n<p>In this course, you will dive into the magic of Mockito. You will learn about Mocks, Spies and Partial Mocks, and their corresponding Stubbing behaviour. You will also see the process of Verification with Test Doubles and Object Matchers. Finally, Test Driven Development (TDD) with Mockito is discussed in order to see how this library fits in the concept of TDD. Check it out <a href=\"http:\/\/www.javacodegeeks.com\/2015\/09\/testing-with-mockito\/\">here<\/a>!<\/em><\/p>\n<div class=\"toc\">\n<h4>Table Of Contents<\/h4>\n<dl>\n<dt><a href=\"#verification\">1. What is Verification?<\/a><\/dt>\n<dt><a href=\"#verify\">2. Using verify()<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#built_in\">2.1. Using the built in Verification Modes<\/a><\/dt>\n<dt><a href=\"#verification_mode\">2.2. Creating a custom Verification Mode<\/a><\/dt>\n<dt><a href=\"#parameters\">2.3. Verification with Parameters<\/a><\/dt>\n<dt><a href=\"#timeout\">2.4. Verification with Timeout<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#no_interactions\">3. Verifying No Interactions and No More Interactions<\/a><\/dt>\n<dt><a href=\"#in_order\">4. Verification in Order<\/a><\/dt>\n<dt><a href=\"#captors\">5. Argument Captors<\/a><\/dt>\n<dt><a href=\"#conclusion\">6. Conclusion<\/a><\/dt>\n<dt><a href=\"#code\">7. Download the Source Code<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><a name=\"verification\"><\/a>1. What is Verification?<\/h2>\n<p>Verification is the process of confirming the behaviour of a Mock. It is useful in determining that the class we are testing has interacted in an expected way with any of its dependencies. Sometimes we aren\u2019t interested in the values which are returned from a Mock, but are instead interested in how the class under test interacted with it, what values were sent in or how often it was called. The process of confirming this behaviour is verification and there are a number of tools which Mockito provides to allow us to do it.<\/p>\n<h2><a name=\"verify\"><\/a>2. Using verify()<\/h2>\n<p>The main tool for performing verification in the Mockito toolbox is the <code>org.mockito.Mockito.verify()<\/code> method. The verify method takes the Mock object as a parameter and returns an instance of the same Class as the Mock, allowing you to call the methods of the Class, which Mockito interprets as a request to verify that there was some interaction with that method.<\/p>\n<p>Let\u2019s look again at our printer interface from the previous tutorial.<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\npublic interface Printer {\n\t\n\tvoid printTestPage();\n\n}\n<\/pre>\n<p>We can create a simple unit test to demonstrate verify using a Mock Printer<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\nimport static org.mockito.Mockito.verify;\n\nimport org.junit.Test;\nimport org.junit.runner.RunWith;\nimport org.mockito.Mock;\nimport org.mockito.runners.MockitoJUnitRunner;\n\n@RunWith(MockitoJUnitRunner.class)\npublic class PrinterTest {\n\n\t@Mock\n\tprivate Printer printer;\n\n\t@Test\n\tpublic void simple_interaction_verification() {\n\t\t\/\/ Given\n\t\t\n\t\t\/\/ When\n\t\tprinter.printTestPage();\n\t\t\n\t\t\/\/ Then\n\t\tverify(printer).printTestPage();\t\t\n\t}\n}\n<\/pre>\n<p>We can see that our unit test firstly calls <code>printer.printTestPage()<\/code>. This is simulating a possible interaction within a class under test, but to keep things simple we are doing it out in the unit test class. The next call is the call to <code>verify(printer).printTestPage()<\/code>. This instructs Mockito to check if there has been a single call to the <code>printTestPage()<\/code> method of the Mock Printer.<\/p>\n<p>Note carefully the syntax of the call, the parameter of <code>verify()<\/code> is the Mock object, not the method call. If we had put <code>verify(printer.printTestPage())<\/code> we would have generated a compile error. Contrast this to the given\/when syntax in stubbing which takes the form <code>when(mockObject.someMethod()).thenReturn(...)<\/code>.<\/p>\n<p>If we hadn\u2019t called <code>printTestPage()<\/code> above this call to verify Mockito would have generated a verification error informing us that there was no invocation of <code>printTestPage()<\/code>, which would look like this:<\/p>\n<pre class=\"brush:shell;wrap-lines:false\">\nWanted but not invoked:\nprinter.printTestPage();\n-&gt; at com.javacodegeeks.hughwphamill.mockito.stubbing.PrinterTest.simple_interaction_verification(PrinterTest.java:24)\nActually, there were zero interactions with this mock.\n<\/pre>\n<p>Additionally if we had made a second call to <code>printTestPage()<\/code> Mockito would have generated a verification error informing us that there were too many invocations of <code>printTestPage()<\/code>. This error would look like this:<\/p>\n<pre class=\"brush:shell;wrap-lines:false\">\norg.mockito.exceptions.verification.TooManyActualInvocations: \nprinter.printTestPage();\nWanted 1 time:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.stubbing.PrinterTest.simple_interaction_verification(PrinterTest.java:25)\nBut was 2 times. Undesired invocation:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.stubbing.PrinterTest.simple_interaction_verification(PrinterTest.java:22)\n<\/pre>\n<p>Usefully the error informs us which line of code contained the superfluous invocation &#8211; in this case line 22 of <code>PrinterTest.java<\/code>.<\/p>\n<p>But what if we want multiple interactions with our Mock?  Does Mockito support this?  Unsurprisingly the answer is Yes!<\/p>\n<p>The <code>verify()<\/code> method takes a second parameter of type <code>org.mockito.verification.VerificationMode<\/code> which can be used to provide additional details about the desired interactions with the mock.<\/p>\n<h3><a name=\"built_in\"><\/a>2.1. Using the built in Verification Modes<\/h3>\n<p>As usual Mockito provides a number of convenient static methods in org.mockito.Mockito for creating VerificationModes, such as:<\/p>\n<p><code>times(int)<\/code><br \/>\nThis will verify that the method was called the input number of times.<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void simple_interaction_verification_times_1() {\n\t\/\/ Given\n\t\t\n\t\/\/ When\n\tprinter.printTestPage();\n\t\t\n\t\/\/ Then\n\tverify(printer, times(1)).printTestPage();\t\t\n}\n<\/pre>\n<p>Note that <code>verify(mock)<\/code> is an alias of <code>verify(mock, times(1))<\/code>.<\/p>\n<p>Of course we can verify multiple interactions using <code>times()<\/code><\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void simple_interaction_verification_times_3() {\n\t\/\/ Given\n\t\t\n\t\/\/ When\n\tprinter.printTestPage();\n\tprinter.printTestPage();\n\tprinter.printTestPage();\n\t\t\n\t\/\/ Then\n\tverify(printer, times(3)).printTestPage();\t\t\n}\n<\/pre>\n<p>This <code>VerificationMode<\/code> will generate useful errors when the actual number of invocations doesn\u2019t match the expected number.<\/p>\n<p>Not enough invocations:<\/p>\n<pre class=\"brush:shell;wrap-lines:false\">\norg.mockito.exceptions.verification.TooLittleActualInvocations: \nprinter.printTestPage();\nWanted 3 times:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.stubbing.PrinterTest.simple_interaction_verification_times_3(PrinterTest.java:49)\nBut was 2 times:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.stubbing.PrinterTest.simple_interaction_verification_times_3(PrinterTest.java:45)\n<\/pre>\n<p>Too many invocations:<\/p>\n<pre class=\"brush:shell;wrap-lines:false\">\norg.mockito.exceptions.verification.TooManyActualInvocations: \nprinter.printTestPage();\nWanted 3 times:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.stubbing.PrinterTest.simple_interaction_verification_times_3(PrinterTest.java:50)\nBut was 4 times. Undesired invocation:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.stubbing.PrinterTest.simple_interaction_verification_times_3(PrinterTest.java:47)\n<\/pre>\n<p><code>atLeastOnce()<\/code>, <code>atLeast(int)<\/code><br \/>\nThis will verify that the method was called at least the given number of times.<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void simple_interaction_verification_atleastonce() {\n\t\/\/ Given\n\t\t\n\t\/\/ When\n\tprinter.printTestPage();\n\tprinter.printTestPage();\n\t\t\n\t\/\/ Then\n\tverify(printer, atLeastOnce()).printTestPage();\t\t\n}\n<\/pre>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void simple_interaction_verification_atleast_2() {\n\t\/\/ Given\n\t\t\n\t\/\/ When\n\tprinter.printTestPage();\n\tprinter.printTestPage();\n\tprinter.printTestPage();\n\t\t\n\t\/\/ Then\n\tverify(printer, atLeast(2)).printTestPage();\t\t\n}\n<\/pre>\n<p>As usual we get comprehensive error reporting:<\/p>\n<pre class=\"brush:shell;wrap-lines:false\">\norg.mockito.exceptions.verification.TooLittleActualInvocations: \nprinter.printTestPage();\nWanted *at least* 2 times:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.stubbing.PrinterTest.simple_interaction_verification_atleast_2(PrinterTest.java:76)\nBut was 1 time:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.stubbing.PrinterTest.simple_interaction_verification_atleast_2(PrinterTest.java:71)\n<\/pre>\n<p><code>atMost(int)<\/code><br \/>\nThis will verify that the method was called at most the given number of times.<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void simple_interaction_verification_atmost_3() {\n\t\/\/ Given\n\t\t\n\t\/\/ When\n\tprinter.printTestPage();\n\tprinter.printTestPage();\n\t\t\n\t\/\/ Then\n\tverify(printer, atMost(3)).printTestPage();\t\t\n}\n<\/pre>\n<p>And the error condition:<\/p>\n<pre class=\"brush:shell;wrap-lines:false\">\norg.mockito.exceptions.base.MockitoAssertionError: \nWanted at most 3 times but was 4\n\tat com.javacodegeeks.hughwphamill.mockito.stubbing.PrinterTest.simple_interaction_verification_atmost_3(PrinterTest.java:91)\n<\/pre>\n<p><code>never()<\/code><br \/>\nThis will verify that the method was not called.<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void simple_interaction_verification_never() {\n\t\/\/ Given\n\t\t\n\t\/\/ When\n\t\t\n\t\/\/ Then\n\tverify(printer, never()).printTestPage();\t\t\n}\n<\/pre>\n<p>And the error condition:<\/p>\n<pre class=\"brush:shell;wrap-lines:false\">\norg.mockito.exceptions.verification.NeverWantedButInvoked: \nprinter.printTestPage();\nNever wanted here:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.stubbing.PrinterTest.simple_interaction_verification_never(PrinterTest.java:102)\nBut invoked here:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.stubbing.PrinterTest.simple_interaction_verification_never(PrinterTest.java:98)\n<\/pre>\n<p><code>only()<\/code><br \/>\nThis will verify that the method being verified was the only method of the mock called.<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void simple_interaction_verification_only() {\n\t\/\/ Given\n\t\t\n\t\/\/ When\n\tprinter.printTestPage();\n\t\t\n\t\/\/ Then\n\tverify(printer, only()).printTestPage();\t\t\n}\n<\/pre>\n<p>We can produce an error by adding the following method to our printer interface:<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\nvoid turnOff();\n<\/pre>\n<p>And calling it in our test<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void simple_interaction_verification_only_fails() {\n\t\/\/ Given\n\t\t\n\t\/\/ When\n\tprinter.printTestPage();\n\tprinter.turnOff();\n\t\t\n\t\/\/ Then\n\tverify(printer, only()).printTestPage();\t\t\n}\n<\/pre>\n<p>to give the following error:<\/p>\n<pre class=\"brush:shell;wrap-lines:false\">\norg.mockito.exceptions.verification.NoInteractionsWanted: \nNo interactions wanted here:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.stubbing.PrinterTest.simple_interaction_verification_only_fails(PrinterTest.java:124)\nBut found this interaction:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.stubbing.PrinterTest.simple_interaction_verification_only_fails(PrinterTest.java:120)\n***\nFor your reference, here is the list of all invocations ([?] - means unverified).\n1. [?]-&gt; at com.javacodegeeks.hughwphamill.mockito.stubbing.PrinterTest.simple_interaction_verification_only_fails(PrinterTest.java:120)\n2. [?]-&gt; at com.javacodegeeks.hughwphamill.mockito.stubbing.PrinterTest.simple_interaction_verification_only_fails(PrinterTest.java:121)\n<\/pre>\n<h3><a name=\"verification_mode\"><\/a>2.2. Creating a custom Verification Mode<\/h3>\n<p>You can create your own custom verification mode by implementing the <code>org.mockito.verification.VerificationMode<\/code> interface. Note that this is using some classes that don\u2019t form part of the public API of Mockito. There are plans to promote them to public API as of the time of writing, but this feature should be used with caution in case the implementation changes before that happens.<\/p>\n<p><code>VerificationMode<\/code> exposes a single <code>void verify(VerificationData data)<\/code> method which is used to verify that the mock invocations we are interested in happend correctly.<\/p>\n<p>You can use a couple of internal Mockito classes to help you in your <code>VerificationMode<\/code>:<\/p>\n<ul>\n<li><code>InvocationsFinder<\/code> will return a list of all invocations with the mock of interest.<\/li>\n<li><code>InvocationMarker<\/code> can be used to mark the mock invocation as verified.<\/li>\n<li><code>Reporter<\/code> exposes a number of shortcut methods for throwing various <code>VerificationFailure<\/code> errors.<\/li>\n<li><code>InvocationMatcher<\/code> is used in conjunction with <code>InvocationsMarker<\/code> to find the desired Invocations if they happened.<\/li>\n<\/ul>\n<p>We are going to create a <code>VerificationMode<\/code> called <code>First<\/code> which will verify that a given method was the first invocation on the Mock. We will create a class which implements <code>VerificationMode<\/code> and in the verify method we will find all matching invocations and verify two things:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>1.\tThe invocation we wanted actually happened, if it did not we will use Reporter to throw a &#8220;wanted but not invoked&#8221; error.<br \/>\n2.\tThe invocation we wanted was the first invocation on the Mock, if it was not we will throw a new exception with an appropriate message detailing the expected invocation and the actual one.<\/p>\n<p>Lastly we will expose the creating of <code>First<\/code> through a static factory method to be consistent with the Mockito syntax.<\/p>\n<p>The class <code>First<\/code> looks like this:<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\npackage com.javacodegeeks.hughwphamill.mockito.verification;\n\nimport java.util.Arrays;\nimport java.util.List;\n\nimport org.mockito.exceptions.Reporter;\nimport org.mockito.exceptions.verification.VerificationInOrderFailure;\nimport org.mockito.internal.debugging.LocationImpl;\nimport org.mockito.internal.invocation.InvocationMarker;\nimport org.mockito.internal.invocation.InvocationMatcher;\nimport org.mockito.internal.invocation.InvocationsFinder;\nimport org.mockito.internal.verification.api.VerificationData;\nimport org.mockito.invocation.Invocation;\nimport org.mockito.verification.VerificationMode;\n\npublic class First implements VerificationMode {\n\t\n\tprivate final InvocationsFinder finder = new InvocationsFinder();\n\tprivate final InvocationMarker marker = new InvocationMarker();\n\tprivate final Reporter reporter = new Reporter();\n\t\n\tpublic static VerificationMode first() {\n\t\treturn new First();\n\t}\n\n\t@Override\n\tpublic void verify(VerificationData data) {\n\t\tList&lt;Invocation&gt; invocations = data.getAllInvocations();\n\t\tInvocationMatcher matcher = data.getWanted();\n\t\t\n\t\tList&lt;Invocation&gt; chunk = finder.findInvocations(invocations, matcher);\n\t\t\n\t\tif (invocations.size() == 0 || chunk.size() == 0) {\n\t\t\treporter.wantedButNotInvoked(matcher);\n\t\t} else if (!sameInvocation(invocations.get(0), chunk.get(0))) {\t\t\t\n\t\t\treportNotFirst(chunk.get(0), invocations.get(0));\n\t\t}\n\t\t\n\t\tmarker.markVerified(chunk.get(0), matcher);\t\n\t}\n\n\tprivate boolean sameInvocation(Invocation left, Invocation right) {\n\t\tif (left == right) {\n\t\t\treturn true;\t\t\t\n\t\t}\t\n\t\treturn left.getMock().equals(right.getMock()) &amp;&amp; left.getMethod().equals(right.getMethod()) &amp;&amp; Arrays.equals(left.getArguments(), right.getArguments());\n\t}\n\t\n\tprivate void reportNotFirst(Invocation wanted, Invocation unwanted) {\n\t\tStringBuilder message = new StringBuilder();\n\t\tmessage.append(\"\\\\nWanted first:\\\\n\").append(wanted).append(\"\\\\n\").append(new LocationImpl());\n\t\tmessage.append(\"\\\\nInstead got:\\\\n\").append(unwanted).append(\"\\\\n\").append(unwanted.getLocation()).append(\"\\\\n\");\n\t\tthrow new VerificationInOrderFailure(message.toString());\n\t\t\n\t}\n}\n<\/pre>\n<p>We can use it in a test case like this:<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void simple_interaction_verification_first() {\n\t\/\/ Given\n\t\t\n\t\/\/ When\n\tprinter.printTestPage();\n\tprinter.turnOff();\t\t\n\t\t\t\t\n\t\/\/ Then\n\tverify(printer, first()).printTestPage();\t\t\n}\n<\/pre>\n<p>Or to catch some unexpected behaviour:<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void simple_interaction_verification_first_fails() {\n\t\/\/ Given\n\t\t\n\t\/\/ When\n\tprinter.turnOff();\n\tprinter.printTestPage();\t\t\t\t\n\t\t\t\t\n\t\/\/ Then\n\tverify(printer, first()).printTestPage();\t\t\n}\n<\/pre>\n<p>Which generates the following error:<\/p>\n<pre class=\"brush:shell;wrap-lines:false\">\norg.mockito.exceptions.verification.VerificationInOrderFailure: \nWanted first:\nprinter.printTestPage();\n-&gt; at com.javacodegeeks.hughwphamill.mockito.verification.PrinterTest.simple_interaction_verification_first_fails(PrinterTest.java:152)\nInstead got:\nprinter.turnOff();\n-&gt; at com.javacodegeeks.hughwphamill.mockito.verification.PrinterTest.simple_interaction_verification_first_fails(PrinterTest.java:148)\n<\/pre>\n<h3><a name=\"parameters\"><\/a>2.3. Verification with Parameters<\/h3>\n<p>We are going to examine verification of methods which take parameters so let\u2019s update our <code>Printer<\/code> interface to add a new method. This method will simulate printing a String of text and will contain the following parameters:<\/p>\n<ul>\n<li>String text &#8211; The text to be printed.<\/li>\n<li>Integer copies &#8211; The number of copies to be made.<\/li>\n<li>Boolean collate &#8211; True to collate copies.<\/li>\n<\/ul>\n<pre class=\"brush:java;wrap-lines:false\">\npublic interface Printer {\n\t\n\tvoid printTestPage();\n\t\n\tvoid turnOff();\n\t\n\tvoid print(String text, Integer copies, Boolean collate);\n\n}\n<\/pre>\n<p>Verification with Parameters lets us verify that not only was there an interaction with a <code>Mock<\/code>, but what parameters were passed to the Mock. To perform verification with parameters you simply pass the parameters of interest into the Mocked method on the verify call on the Mock.<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verificatin_with_actual_parameters() {\n\t\/\/ Given\n\tString text = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, \"\n\t\t\t+ \"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\";\n\tInteger copies = 3;\n\tBoolean collate = true;\n\t\t\n\t\/\/ When\n\tprinter.print(text, copies, collate);\n\t\t\t\t\n\t\/\/ Then\n\tverify(printer).print(text, copies, collate);\t\t\n}\n<\/pre>\n<p>Note carefully again the syntax of <code>verify()<\/code> we are calling <code>print()<\/code> on the object returned from the verify method, not directly on the Mock. You can see that simply passing in the values to <code>print()<\/code> is enough to perform verification using parameters.<\/p>\n<p>The following test will fail:<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verificatin_with_actual_parameters_fails() {\n\t\/\/ Given\n\tString text = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, \"\n\t\t\t+ \"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\";\n\tString text2 = \"Ut enim ad minim veniam, quis nostrud exercitation ullamco \" \n\t\t\t+ \"laboris nisi ut aliquip ex ea commodo consequat.\";\n\tInteger copies = 3;\n\tBoolean collate = true;\n\t\t\n\t\/\/ When\n\tprinter.print(text2, copies, collate);\n\t\t\t\t\n\t\/\/ Then\n\tverify(printer).print(text, copies, collate);\t\t\n}\n<\/pre>\n<p>with the following output:<\/p>\n<pre class=\"brush:shell;wrap-lines:false\">\nArgument(s) are different! Wanted:\nprinter.print(\n    \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\",\n    3,\n    true\n);\n-&gt; at com.javacodegeeks.hughwphamill.mockito.verification.PrinterTest.verificatin_with_actual_parameters_fails(PrinterTest.java:185)\nActual invocation has different arguments:\nprinter.print(\n    \"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\",\n    3,\n    true\n);\n<\/pre>\n<p>You can see that Mockito usefully gives you the expected arguments and the actual arguments in the error trace, making it very easy to debug your failing test.<\/p>\n<p>As with simple verification we can use a VerificationMode to do more specific verification when using Parameters. The crucial difference is that the VerificationMode we specify applies only to invocations with the stated parameters. So if we use a verification mode of <code>never()<\/code>, for instance, we are stating that the method is never called with the stated parameters, not that it is never called at all.<\/p>\n<p>The following test passes because even though the <code>print()<\/code> method is invoked, it is never invoked with the specified parameters.<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verification_with_actual_parameters_and_verification_mode() {\n\t\/\/ Given\n\tString text = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, \"\n\t\t\t+ \"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\";\n\tString text2 = \"Ut enim ad minim veniam, quis nostrud exercitation ullamco \" \n\t\t\t+ \"laboris nisi ut aliquip ex ea commodo consequat.\";\n\tInteger copies = 3;\n\tBoolean collate = true;\n\t\t\n\t\/\/ When\n\tprinter.print(text, copies, collate);\n\t\t\t\t\n\t\/\/ Then\n\tverify(printer, never()).print(text2, copies, collate);\t\t\n}\n<\/pre>\n<p>When we have multiple calls to our <code>Mock<\/code> we can verify each one individually using multiple calls to <code>verify<\/code><\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void multiple_verification_with_actual_parameters() {\n\t\/\/ Given\n\tString text = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, \"\n\t\t\t+ \"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\";\n\tString text2 = \"Ut enim ad minim veniam, quis nostrud exercitation ullamco \" \n\t\t\t+ \"laboris nisi ut aliquip ex ea commodo consequat.\";\n\tInteger copies = 3;\n\tBoolean collate = true;\n\t\t\n\t\/\/ When\n\tprinter.print(text, copies, collate);\n\tprinter.print(text2, copies, collate);\n\t\t\t\t\n\t\/\/ Then\n\tverify(printer).print(text, copies, collate);\n\tverify(printer).print(text2, copies, collate);\t\t\n}\n<\/pre>\n<p>A lot of the time we aren\u2019t interested or don\u2019t know what the actual parameters of the interaction will be, in these instances, just as in the Stubbing phase we can use Argument Matchers to verify interactions.<\/p>\n<p>Look at the following test<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verification_with_matchers() {\n\t\/\/ Given\n\tString text = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, \"\n\t\t\t+ \"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\";\n\tString text2 = \"Ut enim ad minim veniam, quis nostrud exercitation ullamco \" \n\t\t\t+ \"laboris nisi ut aliquip ex ea commodo consequat.\";\n\tInteger copies3 = 3;\n\tInteger copies4 = 4;\n\tBoolean doCollate = true;\n\tBoolean doNotCollate = false;\n\t\t\n\t\/\/ When\n\tprinter.print(text, copies3, doCollate);\n\tprinter.print(text2, copies4, doNotCollate);\n\t\t\t\t\n\t\/\/ Then\n\tverify(printer, times(2)).print(anyString(), anyInt(), anyBoolean());\t\t\n}\n<\/pre>\n<p>Note that we call <code>printer.print()<\/code> twice, with completely different parameters each time. We verify both interactions with the Mock on the last line using Argument Matchers. Remember that <code>verify(printer).print()<\/code> implicitly means we want to verify one and only one interaction with the <code>print()<\/code> method on the Mock, so we must include the <code>times(2)<\/code> VerificationMode to ensure we are verifying both interactions with the Mock.<\/p>\n<p>The Argument Matchers used with Verification are the same Argument Matchers used during the Stubbing phase. Please revisit the <a href=\"http:\/\/www.javacodegeeks.com\/2015\/09\/mocks-spies-and-partial-mocks\/\">Stubbing tutorial<\/a> for a longer list of available Matchers.<\/p>\n<p>As with the Stubbing phase we cannot mix and match Argument Matchers with real values, but what if we didn\u2019t care about the text that was passed into the Printer for printing, we were only interested in verifying that there should be 5 collated copies?<\/p>\n<p>In this case, as with Stubbing, we can use the <code>eq()<\/code> Matcher to verify the real values we are interested, while using <code>anyString()<\/code> for the text.<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verification_with_mixed_matchers() {\n\t\/\/ Given\n\tString text = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, \"\n\t\t\t+ \"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\";\n\tString text2 = \"Ut enim ad minim veniam, quis nostrud exercitation ullamco \" \n\t\t\t+ \"laboris nisi ut aliquip ex ea commodo consequat.\";\n\tInteger copies = 5;\n\tBoolean collate = true;\n\t\t\n\t\/\/ When\n\tprinter.print(text, copies, collate);\n\tprinter.print(text2, copies, collate);\n\t\t\t\t\n\t\/\/ Then\n\tverify(printer, times(2)).print(anyString(), eq(copies), eq(collate));\t\t\n}\n<\/pre>\n<p>This passes, while the following test will fail<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verification_with_mixed_matchers_fails() {\n\t\/\/ Given\n\tString text = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, \"\n\t\t\t+ \"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\";\n\tInteger copies5 = 5;\n\tInteger copies10 = 10;\n\tBoolean collate = true;\n\t\t\n\t\/\/ When\n\tprinter.print(text, copies10, collate);\n\t\t\t\t\n\t\/\/ Then\n\tverify(printer).print(anyString(), eq(copies5), eq(collate));\t\t\n}\n<\/pre>\n<h3><a name=\"timeout\"><\/a>2.4. Verification with Timeout<\/h3>\n<p>Sometimes, when testing multithreaded applications, we want to ensure that certain mock interactions happen within a given timeout period. Mockito provides a <code>timeout()<\/code> method to help us achieve this.<\/p>\n<p>Please note that while this feature is available, the Mockito documentation cautions against using it:<\/p>\n<p>&#8220;It feels this feature should be used rarely &#8211; figure out a better way of testing your multi-threaded system.&#8221;<\/p>\n<p>So with the health warning out of the way let\u2019s look at a couple of examples.<\/p>\n<p>Let\u2019s say we have some thread that\u2019s going to execute a <code>printTestPage()<\/code> and we want to verify that this happens within 100 milliseconds. We can use <code>timeout(100)<\/code> to achieve this. It can be passed as the second parameter to <code>verify()<\/code> and it returns a VerificationWithTimout which is an extension of VerificationMode.<\/p>\n<p>The following test demonstrates it\u2019s usage:<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verification_with_timeout() {\n\t\/\/ Given\n\t\t\n\t\/\/ When\n\tExecutors.newFixedThreadPool(1).execute(() -&gt; printer.printTestPage());\n\t\t\t\t\n\t\/\/ Then\n\tverify(printer, timeout(100)).printTestPage();\n}\n<\/pre>\n<p>Here we create a new <code>ExecutorService<\/code> using <code>Executor<\/code>s which can execute Runnables. We take advantage of Java 8 Lambda expressions to build a new <code>Runnable<\/code> on the fly which will execute a call to <code>printTestPage()<\/code>. We then call <code>verify()<\/code> passing in a timeout of 100ms.<\/p>\n<p>We can look at a failing test now. This time we will use a method reference to generate the Runnable, this is because the body of our Runnable is a bit more complex &#8211; it introduces a sleep for 200ms.<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verification_with_timeout_fails() throws InterruptedException {\n\t\/\/ Given\n\t\t\n\t\/\/ When\n\tExecutors.newFixedThreadPool(1).execute(this::printTestWithSleep);\n\t\t\t\n\t\/\/ Then\n\tverify(printer, timeout(100)).printTestPage();\n}\n\t\nprivate void printTestWithSleep() {\n\ttry {\n\t\tThread.sleep(200L);\n\t\tprinter.printTestPage();\n\t} catch (InterruptedException e) {\n\t\t\/\/ TODO Auto-generated catch block\n\t\te.printStackTrace();\n\t}\n}\n<\/pre>\n<p>The test fails with a simple &#8216;wanted but not invoked&#8217; message.<\/p>\n<p>It is also possible to add VerificationModes to <code>timeout()<\/code> using methods exposed by the returned <code>VerificationWithTimeout<\/code>.<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verification_with_timeout_with_verification_mode() {\n\t\/\/ Given\n\tint poolsize = 5;\n\t\n\t\/\/ When\n\tExecutorService service = Executors.newFixedThreadPool(poolsize);\n\tservice.execute(this::printTestWithSleep);\n\tservice.execute(this::printTestWithSleep);\n\tservice.execute(this::printTestWithSleep);\n\t\t\t\t\n\t\/\/ Then\n\tverify(printer, timeout(500).times(3)).printTestPage();\n}\n<\/pre>\n<p>Here we use the test with sleep to execute <code>printTestPage()<\/code> 3 times, we use an <code>ExecutorService<\/code> that can run 5 parallel threads so the sleeps happen at the same time, allowing all 3 invocations to occur within the 500ms limit.<\/p>\n<p>We can make the test fail by reducing the number of available threads to 1, forcing the printTestWithSleep calls to execute sequentially and going over the 500ms timeout.<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verification_with_timeout_with_verification_mode_fails() {\n\t\/\/ Given\n\tint poolsize = 1;\n\t\n\t\/\/ When\n\tExecutorService service = Executors.newFixedThreadPool(poolsize);\n\tservice.execute(this::printTestWithSleep);\n\tservice.execute(this::printTestWithSleep);\n\tservice.execute(this::printTestWithSleep);\n\t\t\t\t\n\t\/\/ Then\n\tverify(printer, timeout(500).times(3)).printTestPage();\n}\n<\/pre>\n<p>The first 2 calls happen within 400ms while the last one will happen after 600ms, causing the timeout of 500ms to fail with the following output:<\/p>\n<pre class=\"brush:shell;wrap-lines:false\">\norg.mockito.exceptions.verification.TooLittleActualInvocations: \nprinter.printTestPage();\nWanted 3 times:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.verification.PrinterTest.verification_with_timeout_with_verification_mode_fails(PrinterTest.java:410)\nBut was 2 times:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.verification.PrinterTest.printTestWithSleep(PrinterTest.java:376)\n<\/pre>\n<h2><a name=\"no_interactions\"><\/a>3. Verifying No Interactions and No More Interactions<\/h2>\n<p>We saw already that we can use the <code>never()<\/code> VerificationMode to ensure that a particular method of a Mock is not invoked, but what about verifying that there are no interactions on a Mock at all?<\/p>\n<p>Mockito provides us with the <code>verifyZeroInteractions()<\/code> method to do just that. This method uses varargs to allow us to verify no interactions with several mocks in one line of code.<\/p>\n<p>Let\u2019s add some other Mock to our test class:<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Mock\nprivate List&lt;String&gt; list;\n<\/pre>\n<p>Now we can write the following simplistic test to verify no interactions with the Printer or the List<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verify_zero_interactions() {\n\t\/\/ Given\n\t\t\n\t\/\/ When\n\t\t\t\t\n\t\/\/ Then\n\tverifyZeroInteractions(printer, list);\t\t\n}\n<\/pre>\n<p>As usual, the following test will fail<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verify_zero_interactions_fails() {\n\t\/\/ Given\n\t\t\n\t\/\/ When\n\tprinter.printTestPage();\n\t\t\t\t\n\t\/\/ Then\n\tverifyZeroInteractions(printer, list);\t\t\n}\n<\/pre>\n<p>With the following output<\/p>\n<pre class=\"brush:shell;wrap-lines:false\">\norg.mockito.exceptions.verification.NoInteractionsWanted: \nNo interactions wanted here:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.verification.PrinterTest.verify_zero_interactions_fails(PrinterTest.java:288)\nBut found this interaction:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.verification.PrinterTest.verify_zero_interactions_fails(PrinterTest.java:285)\nActually, above is the only interaction with this mock.\n\tat com.javacodegeeks.hughwphamill.mockito.verification.PrinterTest.verify_zero_interactions_fails(PrinterTest.java:288)\n<\/pre>\n<p>We can also verify that once a certain number of invocations have been verified there are no more interactions with the Mock, using the <code>verifyNoMoreInteractions()<\/code> method.<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verify_no_more_interactions() {\n\t\/\/ Given\n\tString text = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, \"\n\t\t\t+ \"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\";\n\tInteger copies = 3;\n\tBoolean collate = true;\n\t\t\n\t\/\/ When\n\tprinter.print(text, copies, collate);\n\t\t\t\t\n\t\/\/ Then\n\tverify(printer).print(text, copies, collate);\n\tverifyNoMoreInteractions(printer);\n}\n<\/pre>\n<p>You can see above that we verify the call to <code>print()<\/code> and then verify that there are no more interactions with the Mock.<\/p>\n<p>The following test will fail because there was an additional interaction with the mock after the verified call to <code>print()<\/code><\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verify_no_more_interactions_fails() {\n\t\/\/ Given\n\tString text = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, \"\n\t\t\t+ \"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\";\n\tInteger copies = 3;\n\tBoolean collate = true;\n\t\t\n\t\/\/ When\n\tprinter.print(text, copies, collate);\n\tprinter.turnOff();\n\t\t\t\t\n\t\/\/ Then\n\tverify(printer).print(text, copies, collate);\n\tverifyNoMoreInteractions(printer);\n}\n<\/pre>\n<p>The failing test generates the following message:<\/p>\n<pre class=\"brush:shell;wrap-lines:false\">\norg.mockito.exceptions.verification.NoInteractionsWanted: \nNo interactions wanted here:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.verification.PrinterTest.verify_no_more_interactions_fails(PrinterTest.java:342)\nBut found this interaction:\n-&gt; at com.javacodegeeks.hughwphamill.mockito.verification.PrinterTest.verify_no_more_interactions_fails(PrinterTest.java:338)\n***\nFor your reference, here is the list of all invocations ([?] - means unverified).\n1. -&gt; at com.javacodegeeks.hughwphamill.mockito.verification.PrinterTest.verify_no_more_interactions_fails(PrinterTest.java:337)\n2. [?]-&gt; at com.javacodegeeks.hughwphamill.mockito.verification.PrinterTest.verify_no_more_interactions_fails(PrinterTest.java:338)\n<\/pre>\n<p>[ulp id=&#8217;JlDLc89DLzIPpdrn&#8217;]<br \/>\n&nbsp;<\/p>\n<h2><a name=\"in_order\"><\/a>4. Verification in Order<\/h2>\n<p>Sometimes we want to verify that interactions with our Mocks happened in a particular order. Mockito provides a class called <code>InOrder<\/code> to help us achieve this.<\/p>\n<p>The first thing we need to do is register the mocks that we want to confirm the invocation order on with the InOrder object. We then execute methods on the Mock object, and then call the <code>verify()<\/code> method of the <code>InOrder<\/code> object for each mock method for which we want to confirm the ordered executions, in the order in which we want to verify they happened.<\/p>\n<p>The <code>InOrder.verify()<\/code> method behaves almost like the standard <code>verify()<\/code> method, allowing you to pass in VerificationModes, however you can\u2019t do Verification With Timeout with InOrder.<\/p>\n<p>Here is an example of verification in order in action:<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verify_in_order() {\n\t\/\/ Given\n\tInOrder inOrder = Mockito.inOrder(printer);\n\t\t\n\t\/\/ When\n\tprinter.printTestPage();\n\tprinter.turnOff();\n\t\t\t\t\n\t\/\/ Then\n\tinOrder.verify(printer).printTestPage();\n\tinOrder.verify(printer).turnOff();\n}\n<\/pre>\n<p>And the converse failing test:<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verify_in_order_fails() {\n\t\/\/ Given\n\tInOrder inOrder = Mockito.inOrder(printer);\n\t\t\n\t\/\/ When\n\tprinter.turnOff();\n\tprinter.printTestPage();\n\t\t\t\t\n\t\/\/ Then\n\tinOrder.verify(printer).printTestPage();\n\tinOrder.verify(printer).turnOff();\n}\n<\/pre>\n<p>Which fails with the following error message:<\/p>\n<pre class=\"brush:shell;wrap-lines:false\">\norg.mockito.exceptions.verification.VerificationInOrderFailure: \nVerification in order failure\nWanted but not invoked:\nprinter.turnOff();\n-&gt; at com.javacodegeeks.hughwphamill.mockito.verification.PrinterTest.verify_in_order_fails(PrinterTest.java:440)\nWanted anywhere AFTER following interaction:\nprinter.printTestPage();\n-&gt; at com.javacodegeeks.hughwphamill.mockito.verification.PrinterTest.verify_in_order_fails(PrinterTest.java:436)\n<\/pre>\n<p>You can also Verify In Order across multiple Mocks:<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verify_in_order_multiple() {\n\t\/\/ Given\n\tInOrder inOrder = Mockito.inOrder(printer, list);\n\t\t\n\t\/\/ When\n\tprinter.printTestPage();\n\tlist.clear();\n\tprinter.turnOff();\n\t\t\t\t\n\t\/\/ Then\n\tinOrder.verify(printer).printTestPage();\n\tinOrder.verify(list).clear();\n\tinOrder.verify(printer).turnOff();\n}\n<\/pre>\n<h2><a name=\"captors\"><\/a>5. Argument Captors<\/h2>\n<p>We have looked at using Argument Matchers for verifying invocations with particular parameters but Mockito lets us go further than this, capturing the parameters which were passed into the invocation and performing asserts directly on them. This is very useful for verifying log in your class which is performed on objects which will be passed to collaborators. The facility for doing this is a class called <code>ArgumentCaptor<\/code> and an annotation called <code>@Captor<\/code>.<\/p>\n<p>Let\u2019s make a new class in our model called <code>PrinterDiagnostics<\/code>. It will contain a Printer and expose a method called <code>diagnosticPrint<\/code>, which will have the same parameters as <code>Printer.print()<\/code> and add some diagnostic information to the text being printed.<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\npackage com.javacodegeeks.hughwphamill.mockito.verification;\n\npublic class PrinterDiagnostics {\n\t\n\tprivate Printer printer;\n\t\n\tpublic PrinterDiagnostics(Printer printer) {\n\t\tthis.printer = printer;\n\t}\n\t\n\tpublic void diagnosticPrint(String text, Integer copies, Boolean collate) {\n\t\tStringBuilder diagnostic = new StringBuilder();\n\t\tdiagnostic.append(\"** Diagnostic Print **\\\\n\");\n\t\tdiagnostic.append(\"*** Copies: \").append(copies).append(\" ***\\\\n\");\n\t\tdiagnostic.append(\"*** Collate: \").append(collate).append(\" ***\\\\n\");\n\t\tdiagnostic.append(\"********************\\\\n\\\\n\");\n\t\t\n\t\tprinter.print(new StringBuilder().append(diagnostic).append(text).toString(), copies, collate);\n\t}\n}\n<\/pre>\n<p>We\u2019ll create a new JUnit test to test this class, using a Mock <code>Printer<\/code> and an <code>ArgumentCaptor<\/code> which we\u2019ll use to verify the input to the Printer.<\/p>\n<p>Here\u2019s the skeleton of the JUnit test:<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\npackage com.javacodegeeks.hughwphamill.mockito.verification;\n\nimport org.junit.Before;\nimport org.junit.runner.RunWith;\nimport org.mockito.ArgumentCaptor;\nimport org.mockito.Captor;\nimport org.mockito.Mock;\nimport org.mockito.runners.MockitoJUnitRunner;\n\n@RunWith(MockitoJUnitRunner.class)\npublic class PrinterDiagnosticsTest {\n\t\n\tprivate PrinterDiagnostics diagnostics;\n\t@Mock\n\tprivate Printer printer;\n\t@Captor\n\tprivate ArgumentCaptor&lt;String&gt; textCaptor;\n\n\t@Before\n\tpublic void setUp() throws Exception {\n\t\tdiagnostics = new PrinterDiagnostics(printer);\n\t}\n}\n<\/pre>\n<p>Here we see that we create an instance of the class under test, diagnostics, a Mock to represent the printer, printer, and an ArgumentCaptor for String arguments to capture the text input to the printer called textCaptor. You can see that we annotated the ArgumentCaptor with the <code>@Captor<\/code> annotation; Mockito will automatically instantiate the ArgumentCaptor for us because we used the annotation.<\/p>\n<p>You can also see that ArgumentCaptor is a Generic type, we create an ArgumentCaptor with Type Argument String in this case because we are going to be capturing the text argument, which is a String. If we were capturing the collate parameter we might have created <code>ArgumentCaptor<Boolean> collateCaptor<\/code>.<\/p>\n<p>In our <code>@Before<\/code> method we simply create a new <code>PrinterDiagnostics<\/code>., injecting our mock Printer through its constructor.<\/p>\n<p>Now let\u2019s create our test. We want to ensure two things:<\/p>\n<p>1.\tThe number of copies is added to the input text.<br \/>\n2.\tThe state of the collate parameter is added to the input text.<br \/>\n3.\tThe original text is maintained.<\/p>\n<p>We could also want to verify the formatting and the asterisks in the real world, but for now let\u2019s content ourselves with verifying the two criteria above.<\/p>\n<p>In the test we will initialize the test data, execute the call to <code>diagnosticPrint()<\/code> and then use <code>verify()<\/code> in conjunction with the <code>capture()<\/code> method of ArgumentCaptor to capture the text argument. We will then do necessary asserts on the captured String to verify the behaviour we expect by using the <code>getValue()<\/code> method to retrieve the captured text.<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verify_diagnostic_information_added_to_text() {\n\t\/\/ Given\n\tString text = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, \"\n\t\t\t+ \"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\";\n\tInteger copies = 3;\n\tBoolean collate = true;\n\tString expectedCopies = \"Copies: \" + copies;\n\tString expectedCollate = \"Collate: \" + collate;\n\t\t\n\t\/\/ When\n\tdiagnostics.diagnosticPrint(text, copies, collate);\n\t\t\n\t\/\/ Then\n\tverify(printer).print(textCaptor.capture(), eq(copies), eq(collate));\n\tassertTrue(textCaptor.getValue().contains(expectedCopies));\n\tassertTrue(textCaptor.getValue().contains(expectedCollate));\n\tassertTrue(textCaptor.getValue().contains(text));\t\n}\n<\/pre>\n<p>Note that <code>capture()<\/code> acts a bit like a Matcher in that you have to use Matchers for the other parameters. We use the <code>eq()<\/code> matcher to ensure we pass through the expected copies and collate parameters.<\/p>\n<p>If there are multiple invocations on the mocked method we can use the <code>getValues()<\/code> method of <code>ArgumentCaptor<\/code> to get a List of all the Strings which were passed through as the text parameter in each call.<\/p>\n<p>Let\u2019s create a new method in PrinterDiagnostics which will perform a diagnostic print of a single collated copy as well as the original print:<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\npublic void diagnosticAndOriginalPrint(String text, Integer copies, Boolean collate) {\n\tdiagnosticPrint(text, copies, collate);\n\tprinter.print(text, copies, collate);\n}\n<\/pre>\n<p>We can now test this with the following test method:<\/p>\n<pre class=\"brush:java;wrap-lines:false\">\n@Test\npublic void verify_diagnostic_information_added_to_text_and_original_print() {\n\t\/\/ Given\n\tString text = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, \"\n\t\t\t+ \"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\";\n\tInteger copies = 3;\n\tBoolean collate = true;\n\tString expectedCopies = \"Copies: \" + copies;\n\tString expectedCollate = \"Collate: \" + collate;\n\t\t\n\t\/\/ When\n\tdiagnostics.diagnosticAndOriginalPrint(text, copies, collate);\n\t\t\n\t\/\/ Then\n\tverify(printer, times(2)).print(textCaptor.capture(), eq(copies), eq(collate));\n\tList&lt;String&gt; texts = textCaptor.getAllValues();\n\tassertEquals(2, texts.size());\n\t\t\n\t\/\/ First captured text is Diagnostic Print\n\tassertTrue(texts.get(0).contains(expectedCopies));\n\tassertTrue(texts.get(0).contains(expectedCollate));\n\tassertTrue(texts.get(0).contains(text));\n\t\t\n\t\/\/ Second captured text is normal Print\n\tassertFalse(texts.get(1).contains(expectedCopies));\n\tassertFalse(texts.get(1).contains(expectedCollate));\n\tassertEquals(text, texts.get(1));\n}\n<\/pre>\n<p>Note that we have to use <code>times(2)<\/code> in our verification because we are expecting to invoke the <code>print()<\/code> method twice.<\/p>\n<p>ArgumentCaptors are particularly useful when our parameters are complex objects or are created by the code under test. You can easily capture the argument and do any type of verification and validation you need on it.<\/p>\n<h2><a name=\"conclusion\"><\/a>6. Conclusion<\/h2>\n<p>We have looked in detail at the verification phase of Mockito. We have examined the ways which we can verify behaviour out of the box, create our own Verification Modes and use Argument Captors for doing further more complex assertions on our Data.<\/p>\n<p>In the next tutorial we will examine how the Hamcrest Matcher library lets us take our test verification even further, allowing us to do very fine grained behavioural validation.<\/p>\n<h2><a name=\"code\"><\/a>7. Download the Source Code<\/h2>\n<p>This was a lesson on Mockito Verification. You may download the source code here: <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/mockito3-verification.zip\">mockito3-verification<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article is part of our Academy Course titled Testing with Mockito. In this course, you will dive into the magic of Mockito. You will learn about Mocks, Spies and Partial Mocks, and their corresponding Stubbing behaviour. You will also see the process of Verification with Test Doubles and Object Matchers. Finally, Test Driven Development &hellip;<\/p>\n","protected":false},"author":582,"featured_media":186,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[460,273],"class_list":["post-44892","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-java","tag-mockito","tag-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Mockito Verification - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"This article is part of our Academy Course titled Testing with Mockito. In this course, you will dive into the magic of Mockito. You will learn about\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Mockito Verification - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"This article is part of our Academy Course titled Testing with Mockito. In this course, you will dive into the magic of Mockito. You will learn about\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2015-11-15T13:24:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-13T09:08:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/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=\"Hugh Hamill\" \/>\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=\"Hugh Hamill\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/mockito-verification.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/mockito-verification.html\"},\"author\":{\"name\":\"Hugh Hamill\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/16859fadb54e0a7d918890100afa9c3e\"},\"headline\":\"Mockito Verification\",\"datePublished\":\"2015-11-15T13:24:33+00:00\",\"dateModified\":\"2023-12-13T09:08:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/mockito-verification.html\"},\"wordCount\":2786,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/mockito-verification.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mockito-logo.jpg\",\"keywords\":[\"Mockito\",\"Testing\"],\"articleSection\":[\"Core Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/mockito-verification.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/mockito-verification.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/mockito-verification.html\",\"name\":\"Mockito Verification - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/mockito-verification.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/mockito-verification.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mockito-logo.jpg\",\"datePublished\":\"2015-11-15T13:24:33+00:00\",\"dateModified\":\"2023-12-13T09:08:56+00:00\",\"description\":\"This article is part of our Academy Course titled Testing with Mockito. In this course, you will dive into the magic of Mockito. You will learn about\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/mockito-verification.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/mockito-verification.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/mockito-verification.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mockito-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mockito-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/11\\\/mockito-verification.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/core-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Mockito Verification\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/16859fadb54e0a7d918890100afa9c3e\",\"name\":\"Hugh Hamill\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g\",\"caption\":\"Hugh Hamill\"},\"description\":\"Hugh is a Senior Software Engineer and Certified Scrum Master based in Galway, Ireland. He achieved his B.Sc. in Applied Computing from Waterford Institute of Technology in 2002 and has been working in industry since then. He has worked for a several large blue chip software companies listed on both the NASDAQ and NYSE.\",\"sameAs\":[\"http:\\\/\\\/www.doubleh.ie\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/hugh-hamill\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Mockito Verification - Java Code Geeks","description":"This article is part of our Academy Course titled Testing with Mockito. In this course, you will dive into the magic of Mockito. You will learn about","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:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html","og_locale":"en_US","og_type":"article","og_title":"Mockito Verification - Java Code Geeks","og_description":"This article is part of our Academy Course titled Testing with Mockito. In this course, you will dive into the magic of Mockito. You will learn about","og_url":"https:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2015-11-15T13:24:33+00:00","article_modified_time":"2023-12-13T09:08:56+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mockito-logo.jpg","type":"image\/jpeg"}],"author":"Hugh Hamill","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Hugh Hamill","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html"},"author":{"name":"Hugh Hamill","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/16859fadb54e0a7d918890100afa9c3e"},"headline":"Mockito Verification","datePublished":"2015-11-15T13:24:33+00:00","dateModified":"2023-12-13T09:08:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html"},"wordCount":2786,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mockito-logo.jpg","keywords":["Mockito","Testing"],"articleSection":["Core Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html","url":"https:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html","name":"Mockito Verification - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mockito-logo.jpg","datePublished":"2015-11-15T13:24:33+00:00","dateModified":"2023-12-13T09:08:56+00:00","description":"This article is part of our Academy Course titled Testing with Mockito. In this course, you will dive into the magic of Mockito. You will learn about","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mockito-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mockito-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2015\/11\/mockito-verification.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/core-java"},{"@type":"ListItem","position":4,"name":"Mockito Verification"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/16859fadb54e0a7d918890100afa9c3e","name":"Hugh Hamill","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g","caption":"Hugh Hamill"},"description":"Hugh is a Senior Software Engineer and Certified Scrum Master based in Galway, Ireland. He achieved his B.Sc. in Applied Computing from Waterford Institute of Technology in 2002 and has been working in industry since then. He has worked for a several large blue chip software companies listed on both the NASDAQ and NYSE.","sameAs":["http:\/\/www.doubleh.ie"],"url":"https:\/\/www.javacodegeeks.com\/author\/hugh-hamill"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/44892","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/582"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=44892"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/44892\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/186"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=44892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=44892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=44892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}