Skip to content

Mocked generic method returns incorrect mocked type #435

@ogray58

Description

@ogray58

Version
JMockit: 1.33
JUnit: 4.11
Java: 1.8.0_66

Description
A mocked generic method will return an instance of the mocked class, instead of a mock matching the type of the parameter. This can be demonstrated with the code below, which produces the following error when run:
java.lang.ClassCastException: package.Class$TestClass cannot be cast to java.lang.String

Code to Reproduce

@Mocked private TestClass mockedTestClass = null;

@Test
public void test()
{
	System.out.println(new TestClass().testMethod("test"));
}

private static class TestClass
{
	public <R> R testMethod(R value)
	{
		return value;
	}
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions