Closed GoogleCodeExporter closed 8 years ago
I've been trying to understand your issue, but I can't even get your example to
compile. Your ChildClass seems to be missing a constructor, and also missing a
return type on the getId() method. Is it supposed to return String, with the
word return inserted at the start of the method? Please clarify.
Cheers,
David.
Original comment by dmwallace.nz
on 5 Dec 2011 at 7:53
Hi David,
I wasn't intending that code example to be run, but rather demonstrate what I
was having difficulty expressing in words. Sorry for wasting your time on that.
It is supposed to be returning a string, I have attached a clarification
example, it not intended to be run, but in theory putting these classes into
separate code files and then running a mockito test should work.
The idea is that the BaseClass is handling common functionality between all
ChildClasses. ChildClasses (with BaseClass help) wrap a ValueType class.
ChildClass exposes the same interface as ValueType and just accesses the
underlying ValueType to return results. Think adapter pattern with some common
functionality rolled into a BaseAdapter.
The problem I'm running into is that if I mock just the ChildClass the
underlying ValueType is null. So any calls to when() on a particular method in
order to stub that method out fail with a nullpointer because the underlying
value object is null. My attempted solution to this was to have ChildClass use
a BaseClass method "getValueType()" then to stub out that method on ChildClass
to return a mocked ValueType Object.
I hope that ^^^ make sense.
Now the issue I ran into is that Mockito appears to be getting confused since
I'm stubbing an inherited method. The "getValueType()" appears to only be
stubbable when I don't stub anything on ChildClass. Once I stub something on
ChildClass, the getValueType() stub appears to be using the subsequent stub
instead, which then gets a type error.
Thanks for looking at this.
-Myles
Original comment by cth...@gmail.com
on 5 Dec 2011 at 5:31
Attachments:
could you make us a small runnable test?
Original comment by brice.du...@gmail.com
on 5 Dec 2011 at 5:43
Hi. I followed your instructions, to build your example. I had to add the
word "return" on line 28. Other than that, no problems.
For me, the test passes. No error from Mockito. Sorry. This was Mockito
1.8.5 on Windows XP. I will try it in 1.9.0-rc1 and let you know how I go.
Original comment by dmwallace.nz
on 6 Dec 2011 at 5:44
OK, I tried 1.9.0-rc1. The test passed. Sorry, but I don't think there's
actually an issue here.
Original comment by dmwallace.nz
on 6 Dec 2011 at 6:22
That's alright, I'm having trouble reproducing it with a simple example right
now, if that changes, I'll reopen this, otherwise I may just be doing something
wrong.
Thanks for your time.
Original comment by cth...@gmail.com
on 6 Dec 2011 at 2:50
Shall we set this issue as invalid?
Original comment by brice.du...@gmail.com
on 13 Jan 2012 at 10:25
Original comment by dmwallace.nz
on 13 Jan 2012 at 10:50
Original issue reported on code.google.com by
cth...@gmail.com
on 2 Dec 2011 at 5:27Attachments: