title: Mocking a suspend function asks for an extra parameter - Mockito
body: <p>I am trying to mock a suspend function which accepts 3 parameters, but when I try to mock it asks for 4 parameters</p>
  <pre><code>  suspend fun notifyBandSuspend(serviceType: String, id: String, action: TimeAction): GenericResponse =
          order.serviceOrderband(serviceType, id, action)
  </code></pre>
  <p>Mocking</p>
  <pre><code>when(repository.notifyBandSuspend(any(), any(), any())).thenReturn(new GenericResponse());
  </code></pre>
  <p>Error is - Expected 4 arguments but found 3</p>
  <p>Imports</p>
  <pre><code>  // Mockito
      testImplementation &quot;org.mockito:mockito-core:2.28.2&quot;
      androidTestImplementation &quot;org.mockito:mockito-core:2.28.2&quot;
      androidTestImplementation &quot;com.linkedin.dexmaker:dexmaker-mockito:2.28.0&quot;
  </code></pre>
  <p>Any idea how to fix this please</p>
  <p>EDIT</p>
  <p>as it was complaining about 4th parameter
  I passed 4 parameters like this</p>
  <pre><code>when(orderRepository.notifyBandSuspend(anyString(), anyString(), any(), any())).thenReturn(new GenericResponse());
  </code></pre>
  <p>that gives me an error:</p>
  <pre><code>org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
  Invalid use of argument matchers!
  3 matchers expected, 4 recorded:
  </code></pre>
  <p>Error</p>
  <pre><code>org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
  Invalid use of argument matchers!
  3 matchers expected, 4 recorded:
  -&gt; at com.xxx.xx.test.scenarios.ServiceOrderViewScenario.setup(ServiceOrderViewScenario.java:46)
  -&gt; at com.xxx.xx.test.scenarios.ServiceOrderViewScenario.setup(ServiceOrderViewScenario.java:46)
  -&gt; at com.xxx.xx.test.scenarios.ServiceOrderViewScenario.setup(ServiceOrderViewScenario.java:46)
  -&gt; at com.xxx.xx.test.scenarios.ServiceOrderViewScenario.setup(ServiceOrderViewScenario.java:46)
  
  This exception may occur if matchers are combined with raw values:
  //incorrect:
  someMethod(anyObject(), &quot;raw String&quot;);
  When using matchers, all arguments have to be provided by matchers.
  For example:
  //correct:
  someMethod(anyObject(), eq(&quot;String by matcher&quot;));
  
  For more info see javadoc for Matchers class.
  
  at com.xxx.xx.clean.orderview.data.OrderRepository.notifyBandSuspend(OrderRepository.kt:22)
  at com.xxx.xx.test.scenarios.ServiceOrderViewScenario.setup(ServiceOrderViewScenario.java:46)
  at com.xxx.xx.test.BaseTest.scenario(BaseTest.java:79)
  at com.xxx.xx.test.ServiceOrderViewTests.testAirStartOrder(ServiceOrderViewTests.java:45)
  at java.lang.reflect.Method.invoke(Native Method)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  at androidx.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
  at androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)
  at androidx.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:527)
  at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
  at org.junit.rules.RunRules.evaluate(RunRules.java:20)
  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
  at androidx.test.runner.AndroidJUnit4.run(AndroidJUnit4.java:104)
  at org.junit.runners.Suite.runChild(Suite.java:128)
  at org.junit.runners.Suite.runChild(Suite.java:27)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
  at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
  at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
  at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
  at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:388)
  at com.xxx.xx.test.runner.UnlockDeviceAndroidJUnitRunner.onStart(UnlockDeviceAndroidJUnitRunner.java:42)
  at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145)
  </code></pre>
  <p>Thanks
  Rao</p>