I'm getting a NoSuchMethodException when I try to call a method of an abstract class that has inherited a method from an interface with a return type of an enum but has not implemented it. If implemented, it works correctly, but does not if unimplemented. I've demonstrated that below, as well as how it works correctly if unimplemented with a non-enum return type, such as a String. I'm using the following:
jmockit: 1.13
junit: 4.11
java: 1.7.0_67
Here is an example in unit test form:
package com.test;
import static org.junit.Assert.assertEquals;
import mockit.Expectations;
import mockit.Mocked;
import mockit.integration.junit4.JMockit;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(JMockit.class)
public class MyAbstractTest {
@Test
public void testEnum(@Mocked final MyAbstractClass myAbstractClass) {
new Expectations() {
{
myAbstractClass.getProperty();
result = Type.TYPE_A;
}
};
Type result = myAbstractClass.getProperty();
assertEquals(Type.TYPE_A, result);
}
@Test
public void testImplementedEnum(@Mocked final MyAbstractClass myAbstractClass) {
new Expectations() {
{
myAbstractClass.getImplementedProperty();
result = Type.TYPE_A;
}
};
Type result = myAbstractClass.getImplementedProperty();
assertEquals(Type.TYPE_A, result);
}
@Test
public void testUnimplementedString(@Mocked final MyAbstractClass myAbstractClass) {
new Expectations() {
{
myAbstractClass.getOtherProperty();
result = "My Mocked Property";
}
};
String result = myAbstractClass.getOtherProperty();
assertEquals("My Mocked Property", result);
}
enum Type {
TYPE_A, TYPE_B;
};
interface MyInterface {
Type getProperty();
Type getImplementedProperty();
String getOtherProperty();
}
abstract class MyAbstractClass implements MyInterface {
@Override
public Type getImplementedProperty() {
return Type.TYPE_B;
}
}
}
For me, testEnum() fails and testImplementedEnum()/testUnimplementedString() work.
I'm getting a NoSuchMethodException when I try to call a method of an abstract class that has inherited a method from an interface with a return type of an enum but has not implemented it. If implemented, it works correctly, but does not if unimplemented. I've demonstrated that below, as well as how it works correctly if unimplemented with a non-enum return type, such as a String. I'm using the following: jmockit: 1.13 junit: 4.11 java: 1.7.0_67
Here is an example in unit test form:
For me, testEnum() fails and testImplementedEnum()/testUnimplementedString() work.