Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
supertim-chen opened this issue Dec 5, 2016 · 2 comments
Closed

Comments

@supertim-chen
Copy link

supertim-chen commented Dec 5, 2016

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

@thekingn0thing
Copy link
Member

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

@thekingn0thing thekingn0thing self-assigned this Dec 5, 2016
@thekingn0thing thekingn0thing added this to the PowerMock 1.6.7 milestone Dec 5, 2016
thekingn0thing pushed a commit that referenced this issue Jan 28, 2017
…class hierarchy for interfaces

Signed-off-by: Arthur Zagretdinov <arthur.zagretdinov@outlook.com>
thekingn0thing pushed a commit that referenced this issue Jan 28, 2017
thekingn0thing pushed a commit that referenced this issue Jan 28, 2017
Pr0methean added a commit to Pr0methean/Glowstone that referenced this issue Jan 31, 2018
Updates PowerMock because otherwise affected by
powermock/powermock#731
@rainierdiaz
Copy link

I fixed this issue by using the right combination of powermock and mockito. In my case it was mockito 1.10.19 and powermock 1.6.2. It still looks there is a bug in 1.6.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants