Generics in Mockito.mock() method

13,119 views
Skip to first unread message

sten

unread,
Dec 28, 2010, 3:45:22 PM12/28/10
to mockito
Hi guys,

Just finished reading Mockito documentation, seems it can save me from
headache I had with EasyMock :-)

I have small suggestion/improvement:

Is it possible to make Mockito support generics in Mockito.mock()
method?
For example code:
final List<String> list = Mockito.mock(List.class);
will produce warning:
Type safety: The expression of type List needs unchecked conversion to
conform to List<String>

I think you can solve it by changing signature of the method from:
public static <T> T mock(Class<T> classToMock)
to:
public static <T> T mock(Class<?> classToMock)

Thanks for amazing framework)))

szczepiq

unread,
Dec 29, 2010, 3:50:25 AM12/29/10
to moc...@googlegroups.com

Hey.

I have a feeling we evaluated this idea in one of the issue report. I believe we discovered a some issues with this approach.

Thanks for feedback! ;)
Cheers!
Szczepan


--
You received this message because you are subscribed to the Google Groups "mockito" group.
To post to this group, send email to moc...@googlegroups.com.
To unsubscribe from this group, send email to mockito+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mockito?hl=en.

Brice Dutheil

unread,
Dec 29, 2010, 4:27:44 AM12/29/10
to moc...@googlegroups.com, moc...@googlegroups.com
Yes, there is an issue on this matter.

As suggested by Szczepan in a previous discussion, I would rather advice you to use @SuppressWarning("unchecked") in your test code. So you can favor readability over verbosity.

Regards,


-- 
Brice
Reply all
Reply to author
Forward
0 new messages