Open cushon opened 9 years ago
Thanks for the detailed report. I agree we should have the type information available somewhere at runtime, but it looks quite tricky to get it. I'll take a look at this when I get a chance (which might be a while), or feel free to give it a try yourself.
To some extent this is an issue with the underlying Mockito implementation. We construct mocks using Mockito's ReturnsMocks
setting, so presumably it would display the same behavior if used directly. It would be nice if there were a solution that worked by changing how we used mockito rather than adding additional logic on top of that. One thing to explore would be making ReturnsCustomMocks extend ReturnsDeepStubs
rather than ReturnsMocks
. I experimented with this briefly and it solved the issue you reported, but seemed to create others.
I think is is distinct from #50.
In the following example the type of the
UiBinder
is erased when it is mocked, causing aClassCastException
.I think there's type information available at runtime that could be used to fixed this. For example, see mockito's handling of
RETURNS_DEEP_STUBS
with generic types:Here's the example:
Full repro: