Error Mocking Abstract Class With Inherited Methods With Enum Return Type #116

Closed
jamespowenjr opened this Issue Dec 12, 2014 · 1 comment

Comments

2 participants
@jamespowenjr

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.

@rliesenfeld rliesenfeld added the bug label Dec 12, 2014

@rliesenfeld rliesenfeld self-assigned this Dec 12, 2014

@rliesenfeld

This comment has been minimized.

Show comment
Hide comment
@rliesenfeld

rliesenfeld Dec 12, 2014

Member

Ok, thanks for reporting!

Member

rliesenfeld commented Dec 12, 2014

Ok, thanks for reporting!

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