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

Closed
b2064832 opened this Issue Nov 5, 2014 · 1 comment

Comments

2 participants
@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 {
FOO("foo");
private final String value;

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

    public String getValue() {
        return value;
    }
}

public static interface Mockable {
    MyEnum getMyEnum();
}

@Test
public void test(@Mocked final Mockable mockable) throws Exception {
    assertEquals(MyEnum.FOO.getValue(), "foo");
    new NonStrictExpectations() {{ //or Expectations
        mockable.getMyEnum();
        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

@rliesenfeld

This comment has been minimized.

Show comment
Hide comment
@rliesenfeld

rliesenfeld Nov 5, 2014

Member

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.

Member

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