java - Asynchronous callback not invoked during test using Mockito -
i trying test application using mockito framework. following example works perfectly:
val dl = mock(classof[dichlistener]) val = argumentcaptor.forclass(classof[int]) when(dl.test(i.capture())).thencallrealmethod() dl.test(666) i.getvalue shouldbe 666
however, similar (but waiting asynchronous response), next 1 doesn't:
when(dl.echoreqcallback(c.capture(), m.capture())).thencallrealmethod() // not working: // verify(dl).echoreqcallback(c.capture(), m.capture()) n2.sendechorequest("hello!") thread.sleep(1000) println(m.getvalue)
echoreqcallback
called after sendechorequest
, dl
mocked object. echoreqcallback
run response network message, not invoke after line:
n2.sendechorequest("hello!")
i tried using longer sleep
time, result same: callback method not invoked m
variable didn't value.
log: using verify
:
> [info] org.mockito.exceptions.verification.wantedbutnotinvoked: > wanted not invoked: > [info] dichlistener.echoreqcallback( > [info] <capturing argument>, > [info] <capturing argument> > [info] );
using when
:
> [info] org.mockito.exceptions.base.mockitoexception: no argument > value captured! > [info] might have forgotten use argument.capture() in > verify()... > [info] ...or used capture() in stubbing stubbed method not > called. [info] > aware recommended use capture() verify() > [info] > [info] examples of correct argument capturing: > [info] argumentcaptor<person> argument = > argumentcaptor.forclass(person.class); > [info] verify(mock).dosomething(argument.capture()); > [info] assertequals("john", argument.getvalue().getname());
edit: n1
connected n2
. want send echo_request n2
n1
, check if listener (dl
) attach after mocking n1
(n1.listener = dl
) fire echoreqcallback
. logic working beneath testing code.
Comments
Post a Comment