tiebin-zhang / powermock

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

Suppression not working for overridden Methods #364

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Suppression doesn't work if the method that should be suppressed is overridden. 

Example class structure:
class A {

  public void dontCallMe(Object someParameter) {...}
    ...
  }
}

public final class B extends A {
  @Override
  public void dontCallMe(Object someParameter) {...}
    ...
  }  
}

I try suppressing dontCallMe using "suppress(method(B.class, "someMethod", 
Object.class))". This results in the following exception given below.

Workaround: suppress all methods with the same signature 
("suppress(method(B.class, Object.class));"). 

Several matching methods found, please specify the argument parameter types so 
that PowerMock can determine which method you're referring to.
Matching methods in class B were:
void dontCallMe( java.lang.Object.class )
void dontCallMe( java.lang.Object.class )

    at org.powermock.reflect.internal.WhiteboxImpl.throwExceptionWhenMultipleMethodMatchesFound(WhiteboxImpl.java:1821)
    at org.powermock.reflect.internal.WhiteboxImpl.findMethod(WhiteboxImpl.java:1749)
    at org.powermock.api.support.membermodification.MemberMatcher.method(MemberMatcher.java:81)
    at MockTest.hello(MockTest.java:45)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:312)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:296)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:284)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:209)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:148)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:122)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:102)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
    at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:42)

Maven dependencies:
<dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>1.9.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>1.4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito</artifactId>
            <version>1.4.11</version>
            <scope>test</scope>
        </dependency>

Original issue reported on code.google.com by gloeckne...@gmail.com on 25 Jan 2012 at 12:11

GoogleCodeExporter commented 9 years ago
Looks like a bug! Thanks for reporting. It would be really cool if you could 
help out with a patch.

Original comment by johan.ha...@gmail.com on 31 Jan 2012 at 8:02

GoogleCodeExporter commented 9 years ago
I've uploaded a patch for issue 51 that solves this issue.

Original comment by hpb...@gmail.com on 25 Jul 2012 at 9:38

GoogleCodeExporter commented 9 years ago

Original comment by johan.ha...@gmail.com on 25 Jul 2012 at 11:23