No methods matching the name(s) get were found in the class hierarchy #731

Closed
iamsupertim opened this Issue Dec 5, 2016 · 1 comment

Projects

None yet

2 participants

@iamsupertim
iamsupertim commented Dec 5, 2016 edited

I used the following code.

@RunWith(PowerMockRunner.class)
@PrepareForTest( { MyStaticClass.class })
public class MyTest {

@Test
public void ATest() {
    ...

    CheckedFuture<Optional<AType>, AException> mockFuture = mock(CheckedFuture.class);

    Optional<AType> mockTypeOpt = mock(Optional.class);
    try {
        when(mockFuture.get())
          .thenReturn(mockTypeOpt);
    } catch (InterruptedException e) {
        fail(e.getStackTrace().toString());
    } catch (ExecutionException e) {
        fail(e.getStackTrace().toString());
    }

    ...
}

}

CheckedFuture is defined at: https://google.github.io/guava/releases/19.0/api/docs/com/google/common/util/concurrent/CheckedFuture.html.
Optional is defined at: https://google.github.io/guava/releases/19.0/api/docs/com/google/common/base/Optional.html.

But it failed with the following error message.

ATest(a.b.c.MyTest) Time elapsed: 0.104 sec <<< ERROR!
org.powermock.reflect.exceptions.MethodNotFoundException: No methods matching the name(s) get were found in the class hierarchy of class java.lang.Object.
at org.powermock.reflect.internal.WhiteboxImpl.getMethods(WhiteboxImpl.java:1720)
at org.powermock.reflect.internal.WhiteboxImpl.getMethods(WhiteboxImpl.java:1745)
at org.powermock.reflect.internal.WhiteboxImpl.getBestMethodCandidate(WhiteboxImpl.java:983)
at org.powermock.core.MockGateway$MockInvocation.findMethodToInvoke(MockGateway.java:317)
at org.powermock.core.MockGateway$MockInvocation.init(MockGateway.java:356)
at org.powermock.core.MockGateway$MockInvocation.(MockGateway.java:307)
at org.powermock.core.MockGateway.doMethodCall(MockGateway.java:142)
at org.powermock.core.MockGateway.methodCall(MockGateway.java:125)
at a.b.c.MyTest.ATest(MyTest.java:186)

I used powermock-api-mockito and powermock-module-junit4 1.6.6 (in pom.xml).

It works well if I used
@RunWith(MockitoJUnitRunner.class)
instead of
@RunWith(PowerMockRunner.class)
@PrepareForTest( { MyStaticClass.class })

Arthur Zagretdinov thinks that this looks like the case (#709).

The Google group post:
https://groups.google.com/forum/#!msg/powermock/a18R-AP4rC8/sG442Zg1CQAJ

@thekingnothing
Member

Thank you a lot for creating an issue. I'll investigate it.

@thekingnothing thekingnothing self-assigned this Dec 5, 2016
@thekingnothing thekingnothing added this to the PowerMock 1.6.7 milestone Dec 5, 2016
@thekingnothing thekingnothing added a commit that referenced this issue Jan 28, 2017
@thekingnothing thekingnothing Fix issue #731 No methods matching the name(s) get were found in the …
…class hierarchy for interfaces

Signed-off-by: Arthur Zagretdinov <arthur.zagretdinov@outlook.com>
c2fc452
@thekingnothing thekingnothing added a commit that referenced this issue Jan 28, 2017
@thekingnothing thekingnothing Fix issue #731 No methods matching the name(s) get were found in the …
…class hierarchy for interfaces
53bdb4c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment