question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wanted but not invoked on 2.12.0, but not on 2.11.0

See original GitHub issue

After updating Mockito from 2.11.0 to 2.12.0 the following test fails with Wanted but not invoked.

The weird thing is this happens only when running tests using Gradle. Android Studio runs the same test as successful. Just like #1183.

package package.redacted;

import org.junit.Test;
import org.mockito.Mockito;

public class ViewModelTest {

    class View {
        private Runnable actionCallback = null;

        void callAction(Runnable callback) {
            actionCallback = callback;
        }

        void simulateActionCalled() {
            if (actionCallback != null) {
                actionCallback.run();
            }
        }

        void showResult() {
        }
    }

    class ViewModel {

        public ViewModel(final View view) {
            view.callAction(new Runnable() {
                @Override
                public void run() {
                    view.showResult();
                }
            });
        }
    }

    @Test public void test() {
        View view = Mockito.spy(new View());
        ViewModel viewModel = new ViewModel(view);

        view.simulateActionCalled();

        Mockito.verify(view).showResult();
    }
}
Wanted but not invoked:
view.showResult();
-> at package.redacted.ViewModelTest$View.showResult(ViewModelTest.java:22)

However, there were exactly 2 interactions with this mock:
view.callAction(
    package.redacted.ViewModelTest$ViewModel$1@26645040
);
-> at package.redacted.ViewModelTest$ViewModel.<init>(ViewModelTest.java:28)

view.simulateActionCalled();
-> at package.redacted.ViewModelTest.test(ViewModelTest.java:41)


	at package.redacted.ViewModelTest$View.showResult(ViewModelTest.java:22)
	at package.redacted.ViewModelTest.test(ViewModelTest.java:43)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	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 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 org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:114)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:57)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:66)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
	at com.sun.proxy.$Proxy1.processTestClass(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:108)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:146)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:128)
	at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
	at java.lang.Thread.run(Thread.java:748)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
raphwcommented, Nov 13, 2017

Ok, this was just me forgetting how my implementation intially worked. I fixed it locally and will push a fix soon.

2reactions
raphwcommented, Nov 12, 2017

Probably another error in the logic for self-invocation detection. I will have a look!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mockito: Wanted but not invoked - java - Stack Overflow
You're misunderstanding what a mock is. When you're doing MyClass myClass = Mockito.mock(MyClass.class); // ... assertNull(myClass.
Read more >
Mockito 2.12.0 API - Javadoc.io
The Mockito library enables mock creation, verification and stubbing. ... In most cases, this is not the way you want to design your...
Read more >
Log4j – Changes - Apache Logging Services
Log4j 1.2 bridge should not wrap components unnecessarily. ... ErrorHandler is invoked with a LogEvent and Throwable when possible, ...
Read more >
Docker Compose release notes
Fixed docker compose to honor --no-ansi even when deprecated option is requested. Fixed network name and network ID possible ambiguity. e2e: added test...
Read more >
Jackson 2.12 features. (5 Most Wanted features, XML module…
Jackson 2.12.0 was just released on November 29, 2020. It is ... No more Scala 2.10 support (versions 2.11, 2.12 and 2.13 supported),...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found