nazymko / powermock

Automatically exported from code.google.com/p/powermock
0 stars 0 forks source link

Error when using MockPolicy more than once by the same test #129

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Class:
public class Some {
    private static final Logger logger = LoggerFactory.getLogger(Some.class);

    public void test() {
        if (logger.isDebugEnabled()) {
            logger.debug("test");
        }
    }
}

TestClass:
@RunWith(PowerMockRunner.class)
@MockPolicy(Slf4jMockPolicy.class)
@PrepareForTest(Some.class)
public class SomeTest {

    @Test
    public void testTest() {
        Some some = new Some();
        some.test();
        some.test();
    }
}

What is the expected output? What do you see instead?
The test should pass.
The test fails:
    java.lang.IllegalStateException: missing behavior definition for the
preceeding method call isDebugEnabled()

What version of the product are you using? On what operating system?
1.2.5, Windows Vista

Please provide any additional information below.

Original issue reported on code.google.com by mat...@gmail.com on 6 Jul 2009 at 8:18

GoogleCodeExporter commented 8 years ago
This is because you haven't used replayAll() (and optionally verifyAll()). I.e. 
you
must do:

@Test
public void testTest() {
    Some some = new Some();

        replayAll();

    some.test();
    some.test();                
}

This is awkward I know but we'll rewrite the mock policies for the next release 
(or
the release after that :)) and hopefully this can be done automatically. Note 
also
that this is only needed for the EasyMock extension, not the Mockito extension. 
Note
also that you don't need to prepare Some.class for test for the mock policy to 
work.

Original comment by johan.ha...@gmail.com on 7 Jul 2009 at 8:33