java - Mokito throwing WrongTypeOfReturnValue -



java - Mokito throwing WrongTypeOfReturnValue -

logic in implementation class shown below, tried write mock , exception wrongtypeofreturnvalue

/** * update audit , courier log when provider sign document. * @param cmscourierinfo * @param documentinfo * @throws exception */ public boolean doauditprovideresigncompletion(cmscourierinfo cmscourierinfo, documentinfo documentinfo) throws exception { string signertitle = ""; list<participantinfo> participantinfos = documentinfo.getparticipants().getparticipantinfo(); //first participant provider participantinfo participantinfo = participantinfos.get(0); if(stringutils.isnotempty(participantinfo.gettitle())){ signertitle = participantinfo.gettitle(); } //update audit log provider signed info cmscouriercontractmanager.signcontract(cmscourierinfo.getguidstring(), participantinfo.getname(), signertitle, null); //update audit log when document sent internal signer homecoming doauditsentforinternalsigner(cmscourierinfo.getdocumentkey(), documentinfo); }

test

@test public void testupdatecontractstatus() throws exception{ string documentkey = "testkey"; cmscourierinfo = mock(cmscourierinfo.class); when(cmsfactorymanager.findcourier(anystring())).thenreturn(cmscourierinfo); echosigndocumentserviceimpl echosigndocumentservice = spy(documentservice); when(echosigndocumentservice.updatecontractstatus(anystring())).thenreturn(true); dothrow(new runtimeexception()).when(echosigndocumentservice).updatecontractstatus(anystring()); boolean status = echosigndocumentservice.updatecontractstatus(documentkey); assert.assertequals(true, status); }

error

org.mockito.exceptions.misusing.wrongtypeofreturnvalue: boolean cannot returned findcourier() findcourier() should homecoming cmscourierinfo *** if you're unsure why you're getting above error read on. due nature of syntax above problem might occur because: 1. exception *might* occur in wrongly written multi-threaded tests. please refer mockito faq on limitations of concurrency testing. 2. spy stubbed using when(spy.foo()).then() syntax. safer stub spies - - doreturn|throw() family of methods. more in javadocs mockito.spy() method. @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:47) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12) @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:44) @ org.junit.internal.runners.statements.invokemethod.evaluate(invokemethod.java:17) @ org.junit.internal.runners.statements.runbefores.evaluate(runbefores.java:26) @ org.junit.runners.parentrunner.runleaf(parentrunner.java:271) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:70) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:50) @ org.junit.runners.parentrunner$3.run(parentrunner.java:238) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:63) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:236) @ org.junit.runners.parentrunner.access$000(parentrunner.java:53) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:229) @ org.junit.runners.parentrunner.run(parentrunner.java:309) @ org.junit.runner.junitcore.run(junitcore.java:160) @ com.intellij.junit4.junit4ideatestrunner.startrunnerwithargs(junit4ideatestrunner.java:74) @ com.intellij.rt.execution.junit.junitstarter.preparestreamsandstart(junitstarter.java:211) @ com.intellij.rt.execution.junit.junitstarter.main(junitstarter.java:67) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ com.intellij.rt.execution.application.appmain.main(appmain.java:134)

some inputs of great help

i can't explain specific error (i maybe have see more of code). there coding error in test. right before invoke updatecontractstatus(), tell mock thrown exception whenever method called string value. therefore, never homecoming value assigned , never reach assert statement.

also because can't see of code guessing, based on posted error help message, might seek changing stubbing of spy class form:

doreturn(true).when(echosigndocumentservice).updatecontractstatus(anystring());

java mockito

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -