chiffchaff / powermock

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

@PrepareForTest on method not working with PowerMockRule #492

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

The following test running the PowerMOckRule doesn't suppress the 'isNumeric' 
method when @PrepareForTest is on the method. However
it does when @PrepareForTest is on the class.

import static org.junit.Assert.*;

import org.apache.commons.lang.StringUtils;
import org.junit.Rule;
import org.junit.Test;

import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.rule.PowerMockRule;

public class TestFoo {

    @Rule
    public PowerMockRule rule = new PowerMockRule (); 

    @Test
    @PrepareForTest(StringUtils.class)
    public void foo() throws Exception {
         PowerMockito.suppress(PowerMockito.method(StringUtils.class, "isNumeric"));
        assertTrue(StringUtils.isNumeric("12345"));

    }

}

What steps will reproduce the problem?
1.  Run the test using PowerMockRule and with @PrepareForTest on the class
2.  Run the test using PowerMockRule and with @PrepareForTest on the method

What is the expected output? What do you see instead?

The test should fail because the method isNumeric() should be suppresed.
But instead, the test pass. This is because the method has not been
suppresed.

What version of the product are you using? On what operating system?
powermock 1.5.4
eclipse kepler
windows xp
java 6 

Please provide any additional information below.

Original issue reported on code.google.com by enricj...@yahoo.es on 2 Apr 2014 at 3:43