I'm using Mockito in conjunction with Jukito to make my integration testing easier. I have a singleton Guice service that is basically a DAO that returns an iterator. I want to test timeouts, so I would like to return a mock iterator I've created. This mock iterator returns the list of items it was created with, then blocks indefinitely. This is used to test our circuit breakers when we communicate with external systems. We're using Hystrix, so a different thread than the caller will be invoking this iterator. When I attempt to run my test, I receive this exception
14-03-26 13:47:03 INFO collection.guice.MigrationManagerRule.before(36)<main>- Migration complete
org.mockito.exceptions.misusing.WrongTypeOfReturnValue:
MockingIterator cannot be returned by getType()
getType() should return String
***
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. This exception *might* occur in wrongly written multi-threaded tests.
Please refer to Mockito FAQ on limitations of concurrency testing.
2. 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.apache.usergrid.persistence.graph.GraphManagerTimeoutIT.testWriteReadEdgeTypeSource(GraphManagerTimeoutIT.java:137)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.jukito.InjectedStatement.evaluate(InjectedStatement.java:96)
at org.jukito.InjectedBeforeStatements.evaluate(InjectedBeforeStatements.java:51)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.safehaus.guicyfig.EnvironResource$1.evaluate(EnvironResource.java:84)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.jukito.JukitoRunner.run(JukitoRunner.java:166)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
However, when I step through the section of code Mockito is complaining about, it's not the correct serialization invocation. It's actually serialization.getEdgeTypes, that's invoked, not serialization.getEdgesFromSource. I was a bit surprised, since it's trying to apply my spy to the wrong method, it doesn't match my test. Any thoughts on what I'm doing wrong? Here is a link to the test.