noushadali / powermock

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

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

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create the following classes:

public class SimpleOps
{
    public List<String> doStreamStuff(List<String> 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());
    }
}

2. 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
- Junit 4.11
- EasyMock 3.2
- Objenesis 2.1
- JavaAssist 3.18.2-GA

Original issue reported on code.google.com by brad.sta...@gmail.com on 13 Aug 2014 at 3:32

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

Original comment by brad.sta...@gmail.com on 13 Aug 2014 at 3:39

GoogleCodeExporter commented 9 years ago

Original comment by johan.ha...@gmail.com on 28 Aug 2014 at 6:42

GoogleCodeExporter commented 9 years ago
Issue 512 has been merged into this issue.

Original comment by johan.ha...@gmail.com on 28 Aug 2014 at 11:28

GoogleCodeExporter commented 9 years ago

Original comment by johan.ha...@gmail.com on 28 Aug 2014 at 11:28

GoogleCodeExporter commented 9 years ago
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

Original comment by espina.e...@gmail.com on 13 Nov 2014 at 12:39

GoogleCodeExporter commented 9 years ago
Could you add this as another issue?

Original comment by johan.ha...@gmail.com on 13 Nov 2014 at 1:55