I'm writing a test case that uses a java.beans.PropertyDescriptor using Mockito, and I want to mock the behavior of getPropertyType() to return an arbitrary Class> object (in my case, String.class). Normally, I would do that by just invoking:
// we already did an "import static org.mockito.Mockito.*"
when(mockDescriptor.getPropertyType()).thenReturn(String.class);
However, oddly, this does not compile:
cannot find symbol method thenReturn(java.lang.Class)
But when I specify the type parameter instead of depending on inference:
Mockito.>when(mockDescriptor.getPropertyType()).thenReturn(String.class);
everything is hunky dory. Why can't the compiler correctly infer the return type of when() in this case? I have never had to specify the parameter before like that.
解决方案
PropertyDescriptor#getPropertyType() re