Skip to content

Can't use @Mocked on Base classes anymore #236

@rolger

Description

@rolger

I encountered an issue (?) with JMockit 1.20. Until 1.19 I was able to annoted a Base class with @mocked and I could record some behaviour. Since 1.20 the behaviorz changed. The object is mocked but instead of returning the values recorded in the Expectations it provides just the default values.

public final class MockingBaseClassTest {
static class Base {
int getIntValue() { return 1; }
}

static class Bar extends Base {
    int doSomething() { return 1 + getIntValue(); }
}

@Test
public void failsInJMockit120(@Mocked final Base foo) throws Exception {
    new Expectations() {{
            foo.getIntValue(); result = 9;
    }};
    // the result in 1.20
    Assert.assertEquals(9, new Bar().doSomething());
    // the result in 1.19
    Assert.assertEquals(10, new Bar().doSomething());
}

}

Hopefully this is clear enough. Thanks in advance.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions