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

org.powermock.reflect.exceptions.MethodNotFoundException #736

Closed
liting-zhang opened this issue Jan 4, 2017 · 1 comment
Closed

org.powermock.reflect.exceptions.MethodNotFoundException #736

liting-zhang opened this issue Jan 4, 2017 · 1 comment

Comments

@liting-zhang
Copy link

liting-zhang commented Jan 4, 2017

I have mocked a https://github.com/elastic/elasticsearch/blob/master/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java with Powermockito, before it works, but since the code chanage and add below code:

NetworkModule networkModule = new NetworkModule(settings, true, pluginsService.filterPlugins(NetworkPlugin.class), threadPool,
                bigArrays, circuitBreakerService, namedWriteableRegistry, xContentRegistry, networkService);
            final Transport transport = networkModule.getTransportSupplier().get();

the code alway fail at getTransportSupplier().get(), the throws exception:

Caused by: 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.<init>(MockGateway.java:307)
    at org.powermock.core.MockGateway.doMethodCall(MockGateway.java:142)
    at org.powermock.core.MockGateway.methodCall(MockGateway.java:125)
    at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:162)

networkModule.getTransportSupplier() returns Supplier.

here is code from networkModule: https://github.com/elastic/elasticsearch/blob/master/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java

here is the example project:
test.zip

with example code on github: https://github.com/liting-zhang/test

@thekingn0thing
Copy link
Member

Looks like issue has the same cause as #731 which I fixed.

I've tried your example with new build, and I see different error:

2017-01-28 19:15:54.948 [main] WARN  org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/test] in DispatcherServlet with name ''
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 26.613 sec <<< FAILURE! - in test.ExampleTest
test(test.ExampleTest)  Time elapsed: 0.292 sec  <<< FAILURE!
java.lang.AssertionError: Status expected:<200> but was:<404>
	at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:54)
	at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:81)
	at org.springframework.test.web.servlet.result.StatusResultMatchers$10.match(StatusResultMatchers.java:664)
	at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:171)
	at test.ExampleTest.test(ExampleTest.java:52)

I deployed the RC to Bintray. Could you try the RC with your test?

        <repository>
           <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>bintray-powermock-maven</id>
          <name>bintray</name>
          <url>http://dl.bintray.com/powermock/maven</url>
      </repository>

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

2 participants