org.mockito.exceptions.base.MockitoException: 'calculateNewValue' is a *void method* and it *cannot* be stubbed with a * return value*! Voids are usually stubbed with Throwables: doThrow(exception).when(mock).someVoidMethod(); *** If you're unsure why you're getting above error read on. Due to the nature of the syntax above problem might occur because: 1. The method you are trying to stub is *overloaded*. Make sure you are calling the right overloaded version. 2. Somewhere in your test you are stubbing *final methods*. Sorry, Mockito does not verify/stub final methods. 3. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies - - with doReturn|Throw() family of methods. More in javadocs for Mockito. spy() method.

Google Groups | Geert Vermeiren | 2 years ago
  1. 0

    Problem using @Spy: behaves differently in JUnit & JUnit Plugin tests (eclipse, maven)

    Google Groups | 2 years ago | Geert Vermeiren
    org.mockito.exceptions.base.MockitoException: 'calculateNewValue' is a *void method* and it *cannot* be stubbed with a * return value*! Voids are usually stubbed with Throwables: doThrow(exception).when(mock).someVoidMethod(); *** If you're unsure why you're getting above error read on. Due to the nature of the syntax above problem might occur because: 1. The method you are trying to stub is *overloaded*. Make sure you are calling the right overloaded version. 2. Somewhere in your test you are stubbing *final methods*. Sorry, Mockito does not verify/stub final methods. 3. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies - - with doReturn|Throw() family of methods. More in javadocs for Mockito. spy() method.
  2. 0

    "void method cannot be stubbed" error when irrelevant method is called from background thread

    GitHub | 1 year ago | johanhaleby
    org.mockito.exceptions.base.MockitoException: 'callProt' is a *void method* and it *cannot* be stubbed with a *return value*! Voids are usually stubbed with Throwables: doThrow(exception).when(mock).someVoidMethod(); *** If you're unsure why you're getting above error read on. Due to the nature of the syntax above problem might occur because: 1. The method you are trying to stub is *overloaded*. Make sure you are calling the right overloaded version. 2. Somewhere in your test you are stubbing *final methods*. Sorry, Mockito does not verify/stub final methods. 3. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies - - with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.
  3. 0

    Power Mockito for private methods (Testing forum at Coderanch)

    coderanch.com | 8 months ago
    org.mockito.exceptions.base.MockitoException: 'meaningfulPublicApi' is a *void method* and it *cannot* be stubbed with a *return value*! Voids are usually stubbed with Throwables: doThrow(exception).when(mock).someVoidMethod(); *** If you're unsure why you're getting above error read on. Due to the nature of the syntax above problem might occur because: 1. The method you are trying to stub is *overloaded*. Make sure you are calling the right overloaded version. 2. Somewhere in your test you are stubbing *final methods*. Sorry, Mockito does not verify/stub final methods. 3. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies - - with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    PowerMockito doesn't match overloaded method when return types differ

    Stack Overflow | 1 year ago | Christian
    org.mockito.exceptions.base.MockitoException: 'bar' is a *void method* and it *cannot* be stubbed with a *return value*! Voids are usually stubbed with Throwables: doThrow(exception).when(mock).someVoidMethod(); *** If you're unsure why you're getting above error read on. Due to the nature of the syntax above problem might occur because: 1. The method you are trying to stub is *overloaded*. Make sure you are calling the right overloaded version. 2. Somewhere in your test you are stubbing *final methods*. Sorry, Mockito does not verify/stub final methods. 3. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies - - with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.
  6. 0

    Mocking Private Methods

    GitHub | 1 year ago | johanhaleby
    org.mockito.exceptions.base.MockitoException: 'meaningfulPublicApi' is a *void method* and it *cannot* be stubbed with a *return value*! Voids are usually stubbed with Throwables: doThrow(exception).when(mock).someVoidMethod(); *** If you're unsure why you're getting above error read on. Due to the nature of the syntax above problem might occur because: 1. The method you are trying to stub is *overloaded*. Make sure you are calling the right overloaded version. 2. Somewhere in your test you are stubbing *final methods*. Sorry, Mockito does not verify/stub final methods. 3. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies - - with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.

    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.base.MockitoException

      'calculateNewValue' is a *void method* and it *cannot* be stubbed with a * return value*! Voids are usually stubbed with Throwables: doThrow(exception).when(mock).someVoidMethod(); *** If you're unsure why you're getting above error read on. Due to the nature of the syntax above problem might occur because: 1. The method you are trying to stub is *overloaded*. Make sure you are calling the right overloaded version. 2. Somewhere in your test you are stubbing *final methods*. Sorry, Mockito does not verify/stub final methods. 3. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies - - with doReturn|Throw() family of methods. More in javadocs for Mockito. spy() method.

      at org.woozong.CalculatorTest.testCalculation()
    2. org.woozong
      CalculatorTest.testCalculation
      1. org.woozong.CalculatorTest.testCalculation(CalculatorTest.java:25)
      1 frame
    3. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:606)
      4 frames
    4. JUnit
      ParentRunner.run
      1. org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      2. org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      3. org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      4. org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      5. org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
      6. org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
      7. org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
      8. org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
      9. org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      10. org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      11. org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      12. org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      13. org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      14. org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      14 frames
    5. JUnit4 Runner
      JUnit4TestReference.run
      1. org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
      1 frame
    6. JUnit3 Runner
      RemoteTestRunner.run
      1. org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      2. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      4. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      4 frames
    7. PDE JUnit Plug-in Test
      CoreTestApplication.run
      1. org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:62)
      2. org.eclipse.pde.internal.junit.runtime.CoreTestApplication.run(CoreTestApplication.java:23)
      2 frames
    8. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:606)
      4 frames
    9. Equinox Container
      EclipseAppHandle.run
      1. org.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:587)
      2. org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:198)
      2 frames
    10. Eclipse OSGi
      EclipseStarter.run
      1. org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
      2. org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
      3. org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
      4. org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
      4 frames
    11. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:606)
      4 frames
    12. Equinox
      Main.main
      1. org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
      2. org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
      3. org.eclipse.equinox.launcher.Main.run(Main.java:1410)
      4. org.eclipse.equinox.launcher.Main.main(Main.java:1386)
      4 frames