Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException when calling a method on a mocked object when it has a particular class hierarchy. #389

Closed
stephenrobertson0 opened this issue Feb 7, 2017 · 0 comments
Assignees
Labels

Comments

@stephenrobertson0
Copy link

  • 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)
@rliesenfeld rliesenfeld self-assigned this Feb 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants