Hi everyone, I struggle with following problem:
# What steps will reproduce the problem?
- Concrete classes:
1. Create a parent class and a inherting child class
2. create a method in parent and override it in child
3. call super.thatMethod() in child
- Test class:
1. stub parent class method to return a mocked value
2. call on child class the method and save return value
3. look if it got mocked.
# What is the expected output? What do you see instead?
- My Test runs red but should go green.
# What version of the product are you using? On what operating system?
- powermock-api-mockito-1.5.2.jar
# Please provide any additional information below.
These extracts should make it more clear. You can switch between X and Y and
will see that the test will go from green to red as the mocked value won't be
considered anymore.
But that is exactly what I need, I want to stub a simple super delegation call
to the parent class.
PS: Complete code attached, but below code should be enough.
================= Playground =================
public class Playground extends SuperPlayground {
@Override
public int getNumberX() {
// final int number = super.getNumberX();
final int number = super.getNumberY(); // Y works, X not.
return number + 10;
}
}
================= SuperPlayground =================
public class SuperPlayground {
public int getNumberX() {
return 30;
}
public int getNumberY() {
return 30;
}
}
================= PlaygroundTest =================
@RunWith(PowerMockRunner.class)
@PrepareForTest({ SuperPlayground.class, TreeElementUtils.class })
public class PlaygroundTest {
@InjectMocks
Playground spieleWiese;
@Test
public void testSupercallStubbing() {
// prepare
// final Method method = MemberMatcher.method(SuperPlayground.class, "getNumberX");
final Method method = MemberMatcher.method(SuperPlayground.class, "getNumberY");
MemberModifier.stub(method).toReturn(90);
// act
final int gottenNumber = spieleWiese.getNumberX();
// assert
Assert.assertThat(gottenNumber, org.hamcrest.Matchers.is(100));
}
}
Original issue reported on code.google.com by xmarcus89@googlemail.com on 31 Jul 2014 at 10:57
Original issue reported on code.google.com by
xmarcus89@googlemail.com
on 31 Jul 2014 at 10:57Attachments: