- Version of JMockit that was used:
1.30
- Description of the problem:
ClassCastException when calling a method on a mocked object when it has a particular class hierarchy. The following code can be used to reproduce the issue:
`
import org.junit.Test;
import mockit.Mocked;
public class WeirdClassCastErrorTest {
@Mocked
private Class object;
@Test
public void testCreateProduct() {
object.method();
}
private class Class extends BaseClass implements Interface<OtherClass> {
}
private abstract class BaseClass {
public OtherClass method() {
return new OtherClass();
}
}
private interface Interface<T> {
T method();
}
private class OtherClass {
}
}
`
Output from running the code -
java.lang.ClassCastException: WeirdClassCastErrorTest$Class cannot be cast to WeirdClassCastErrorTest$OtherClass
at WeirdClassCastErrorTest$BaseClass.method(WeirdClassCastErrorTest.java)
at WeirdClassCastErrorTest.testCreateProduct(WeirdClassCastErrorTest.java:19)