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

Testing a method that calls Collection.stream() throws an error #533

Closed
johanhaleby opened this issue Jul 25, 2015 · 6 comments
Closed

Testing a method that calls Collection.stream() throws an error #533

johanhaleby opened this issue Jul 25, 2015 · 6 comments

Comments

@johanhaleby
Copy link
Collaborator

From brad.sta...@gmail.com on August 13, 2014 17:32:27

What steps will reproduce the problem? 1. Create the following classes:

public class SimpleOps
{
public List doStreamStuff(List inputs)
{
return inputs.stream().collect(Collectors.toList());
}
}

@RunWith(PowerMockRunner.class)
@PrepareForTest(SimpleOps.class)
public class SimpleOpsTest
{
@test
public void testStream()
{
SimpleOps ops = new SimpleOps();
ops.doStreamStuff(Collections.emptyList());
}
}

  1. Run the test What is the expected output? What do you see instead? I expect to see no output, just a passed test. Instead I see this Error:
    No methods matching the name(s) stream were found in the class hierarchy of class java.util.Collections$EmptyList.
    org.powermock.reflect.exceptions.MethodNotFoundException: No methods matching the name(s) stream were found in the class hierarchy of class java.util.Collections$EmptyList.
    at org.powermock.reflect.internal.WhiteboxImpl.getMethods(WhiteboxImpl.java:1902)
    at org.powermock.reflect.internal.WhiteboxImpl.getMethods(WhiteboxImpl.java:1931)
    at org.powermock.reflect.internal.WhiteboxImpl.getBestMethodCandidate(WhiteboxImpl.java:1025)
    at org.powermock.core.MockGateway.doMethodCall(MockGateway.java:89)
    at org.powermock.core.MockGateway.methodCall(MockGateway.java:168)
    at SimpleOps.doStreamStuff(SimpleOps.java:5)
    at SimpleOpsTest.testStream(SimpleOpsTest.java:9)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:310)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:127)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:82)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:207)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:146)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:118)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:104)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
    at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:53) What version of the product are you using? On what operating system? PowerMock 1.5.5 on Windows 7 (64-bit) Please provide any additional information below. I'm also using the following libraries
  2. Junit 4.11
  3. EasyMock 3.2
  4. Objenesis 2.1
  5. JavaAssist 3.18.2-GA

Original issue: http://code.google.com/p/powermock/issues/detail?id=513

@johanhaleby
Copy link
Collaborator Author

From brad.sta...@gmail.com on August 13, 2014 08:39:19

This is probably related to issue #512 : https://code.google.com/p/powermock/issues/detail?id=512&start=100

@johanhaleby
Copy link
Collaborator Author

From johan.ha...@gmail.com on August 27, 2014 23:42:53

Status: Started

@johanhaleby
Copy link
Collaborator Author

From johan.ha...@gmail.com on August 28, 2014 04:28:02

Issue 512 has been merged into this issue.

@johanhaleby
Copy link
Collaborator Author

From johan.ha...@gmail.com on August 28, 2014 04:28:58

Status: Fixed

@johanhaleby
Copy link
Collaborator Author

From espina.e...@gmail.com on November 13, 2014 04:39:36

Hi,

Thanks for fixing this, but unfortunately it doesn't work on every single default method a type might have.

For example, it works as expected with "stream", but it doesn't work for "forEach". That's because "forEach" is default method of java.util.Iterable

Thanks

@johanhaleby
Copy link
Collaborator Author

From johan.ha...@gmail.com on November 13, 2014 05:55:58

Could you add this as another issue?

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

1 participant