org.mockito.exceptions.misusing.NotAMockException: Argument passed to when() is not a mock! Example of correct stubbing: doThrow(new RuntimeException()).when(mock).someMethod();

Stack Overflow | Karthick | 3 weeks ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    org.mockito.exceptions.misusing.NotAMockException

    Stack Overflow | 3 weeks ago | Karthick
    org.mockito.exceptions.misusing.NotAMockException: Argument passed to when() is not a mock! Example of correct stubbing: doThrow(new RuntimeException()).when(mock).someMethod();
  2. 0

    I get NotAMockException when trying to partially mock a void method - what am I doing wrong?

    Stack Overflow | 1 year ago | Kidburla
    org.mockito.exceptions.misusing.NotAMockException: Argument passed to when() is not a mock! Example of correct stubbing: doThrow(new RuntimeException()).when(mock).someMethod();
  3. 0

    Mockito and AsyncTasks

    Stack Overflow | 11 months ago | Francesc
    org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Misplaced argument matcher detected here: -> at com.xyz.interactor.GetEntryTest.testGetEntry_success(GetEntryTest.java:45) You cannot use argument matchers outside of verification or stubbing. Examples of correct usage of argument matchers: when(mock.get(anyInt())).thenReturn(null); doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject()); verify(mock).someMethod(contains("foo")) Also, this error might show up because you use argument matchers with methods that cannot be mocked. Following methods *cannot* be stubbed/verified: final/private/equals()/hashCode(). Mocking methods declared on non-public parent classes is not supported.
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    stubbing two methods in a mock is throwing Exception using Mockito and Spring MockMVC

    Stack Overflow | 3 years ago | Eduardo Lima
    org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Misplaced argument matcher detected here: -> at com.example.test.api.login.LoginTest.thatLoginUsesStatusOK(LoginTest.java:45) You cannot use argument matchers outside of verification or stubbing. Examples of correct usage of argument matchers: when(mock.get(anyInt())).thenReturn(null); doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject()); verify(mock).someMethod(contains("foo")) Also, this error might show up because you use argument matchers with methods that cannot be mocked. Following methods *cannot* be stubbed/verified: final/private/equals()/hashCode().
  6. 0

    Mockito's spy functionality fails

    Stack Overflow | 9 months ago | Ankit Khettry
    org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be 'a method call on a mock'. For example: when(mock.getArticles()).thenReturn(articles); Also, this error might show up because: 1. you stub either of: final/private/equals()/hashCode() methods. Those methods *cannot* be stubbed/verified. 2. inside when() you don't call method on mock but on some other object. 3. the parent of the mocked class is not public. It is a limitation of the mock engine.

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.mockito.exceptions.misusing.NotAMockException

      Argument passed to when() is not a mock! Example of correct stubbing: doThrow(new RuntimeException()).when(mock).someMethod();

      at com.firstdata.mpl.manager.exampleTest.getexampleFilter_NullFailure()
    2. com.firstdata.mpl
      exampleTest.getexampleFilter_NullFailure
      1. com.firstdata.mpl.manager.exampleTest.getexampleFilter_NullFailure(FuelManagerTest.java:184)
      1 frame
    3. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:497)
      4 frames
    4. JUnit
      ParentRunner.run
      1. org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
      2. org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      3. org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
      4. org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      5. org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      6. org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
      7. org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
      8. org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      9. org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
      10. org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
      11. org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
      12. org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
      13. org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
      14. org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      14 frames
    5. JUnit4 Runner
      JUnit4TestReference.run
      1. org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
      1 frame
    6. JUnit3 Runner
      RemoteTestRunner.main
      1. org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      2. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
      3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:670)
      4. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
      5. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
      5 frames