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

Enum value corrupted after recording expectations in 1.13 #94

b2064832 opened this issue Nov 5, 2014 · 1 comment

Enum value corrupted after recording expectations in 1.13 #94

b2064832 opened this issue Nov 5, 2014 · 1 comment


Copy link

@b2064832 b2064832 commented Nov 5, 2014

JMockit 1.13 corrupts enum values after recording expectations. Version 1.12 is working.
Failing test:

import mockit.Mocked;
import mockit.NonStrictExpectations;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;

public class JMockitEnumTest {
public static enum MyEnum {
private final String value;

    private MyEnum(final String value) {
        this.value = value;

    public String getValue() {
        return value;

public static interface Mockable {
    MyEnum getMyEnum();

public void test(@Mocked final Mockable mockable) throws Exception {
    assertEquals(MyEnum.FOO.getValue(), "foo");
    new NonStrictExpectations() {{ //or Expectations
        result = MyEnum.FOO;
    assertEquals(MyEnum.FOO.getValue(), "foo", "Enum value corrupted after mocking."); // fails here, value null


@rliesenfeld rliesenfeld added the bug label Nov 5, 2014
@rliesenfeld rliesenfeld self-assigned this Nov 5, 2014
Copy link

@rliesenfeld rliesenfeld commented Nov 5, 2014

The enum value is there, but the MyEnum.getValue() method gets mocked, so it returns null. If cascading is disabled (with "@mocked(cascading = false)"), then it doesn't get mocked and the test passes.

This said, since "mockable.getMyEnum()" was explicitly recorded to return a still unmocked enum element, it should have remained unmocked. I will fix that.

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

No branches or pull requests

2 participants