Open GoogleCodeExporter opened 8 years ago
Oops, I must have forgotten about this issue. Let me see...
> when(o).invoke("hello")
when() returns the type of mocked object so 'invoke' will not be available
there.
>I understand I lose compile-time safety, but am I asking something
>unnecessary? I have a case where my classes are generated on the fly and I
>wish to mock their behavior.
Fair enough. compile-time safety is certainly not a goal - rather nice side
effect of
the current api. As far as your suggestion is concerned: You're very welcome to
propose an api and contribute :)
Changing it into an enhancement
Original comment by szcze...@gmail.com
on 9 Jul 2009 at 12:43
Original comment by szcze...@gmail.com
on 9 Jul 2009 at 12:47
>>when() returns the type of mocked object so 'invoke' will not be available
there.
correct, my mistake..intended something like whenInvoked(mock,
"hello").with(..)..
but you got the point anyways...
>>Fair enough. compile-time safety is certainly not a goal - rather nice side
effect of
>>the current api. As far as your suggestion is concerned: You're very welcome
to
propose an api and contribute :)
>>Changing it into an enhancement
Great. thanks!
Original comment by surender...@gmail.com
on 9 Jul 2009 at 4:28
After almost three years situation is the same... I`m really missing this
enhancement now and I think I`ll have to plug PowerMockito only for this
feature. I saw similar behavior there, but not sure it`ll work, it`s designed
for testing private methods:
verifyPrivate(tested).invoke("privateMethodName", argument1);
Original comment by anatoliy...@gmail.com
on 19 Apr 2012 at 7:37
I actually do this already by combining Mockito and FEST-Reflect:
final T spy = spy(injector.getInstance(resourceClass));
Object ongoingMock = doReturn(response).when(spy);
method("getResponse").withReturnType(Response.class).in(ongoingMock).invoke();
This actually works really well, I use it for mocking out some methods in the
superclass of my spied class.
Original comment by m...@talios.com
on 19 Apr 2012 at 7:49
@Anatoliy There was other priorities, it's open source so if you feel you can
contribute a nice Mocking with reflection API we will welcome your pull request.
Original comment by brice.du...@gmail.com
on 21 Apr 2012 at 4:19
We could potentially provide reflect() method (or some name like that) so that
one can do:
when(reflect(mock).call("someMetgod", args)).then ...
doReturn(x).when(reflect(mock)).call("someMethod", args);
Mockito is open source so you know what to do when you need some feature ;)
Original comment by szcze...@gmail.com
on 21 Apr 2012 at 9:39
Original issue reported on code.google.com by
surender...@gmail.com
on 30 Jun 2009 at 9:29