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

Mocked class with method that returns a Throwable subclass throws "not mockable" error #437

Closed
ogray58 opened this Issue Jul 27, 2017 · 2 comments

Comments

3 participants
@ogray58

ogray58 commented Jul 27, 2017

Version
JMockit: 1.33 (Note: I also tried building from the current head of the JMockit master branch and it also failed there)
JUnit: 4.11
Java: 1.8.0_66

Description
I'm guessing that it tries to return a cascaded mock, and since Throwable can't be mocked it throws an error. Note that this doesn't occur if TestClass.getMyThrowable() returns a Throwable instead of a MyThrowable.

Code to Reproduce
ExampleTest.java:

@Mocked private TestClass mockedTestClass = null;

@Test
public void test()
{
	mockedTestClass.getMyThrowable();
}

public static class TestClass
{
	public MyThrowable getMyThrowable()
	{
		return new MyThrowable();
	}
}

public static class MyThrowable extends Throwable {}

@rliesenfeld rliesenfeld self-assigned this Jul 29, 2017

@rliesenfeld rliesenfeld added the bug label Jul 29, 2017

@Milbor

This comment has been minimized.

Show comment
Hide comment
@Milbor

Milbor Jul 31, 2017

Is

    @Injectable
    private IOException exception;

java.lang.IllegalArgumentException: Class java.lang.Throwable is not mockable

same bug or should I open new issue?

Milbor commented Jul 31, 2017

Is

    @Injectable
    private IOException exception;

java.lang.IllegalArgumentException: Class java.lang.Throwable is not mockable

same bug or should I open new issue?

@rliesenfeld

This comment has been minimized.

Show comment
Hide comment
@rliesenfeld

rliesenfeld Aug 7, 2017

Member

@Milbor It's a feature, unless someone can show a legitimate need to mock an exception class, especially a standard one.

Member

rliesenfeld commented Aug 7, 2017

@Milbor It's a feature, unless someone can show a legitimate need to mock an exception class, especially a standard one.

@jmockit jmockit deleted a comment from Milbor Aug 8, 2017

@jmockit jmockit locked and limited conversation to collaborators Aug 8, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.