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

Mocking breaks Java 8 streams framework. #536

Open
johanhaleby opened this issue Jul 25, 2015 · 2 comments
Open

Mocking breaks Java 8 streams framework. #536

johanhaleby opened this issue Jul 25, 2015 · 2 comments

Comments

@johanhaleby
Copy link
Collaborator

From BinisBe...@gmail.com on September 03, 2014 10:31:56

What steps will reproduce the problem? 1. Unzip the eclipse project attached to the issue
2 . Run the unit test. What is the expected output? What do you see instead? Expected the test to pass but it fails with org.powermock.reflect.exceptions.MethodNotFoundException: No methods matching the name(s) stream were found in the class hierarchy of class java.util.ArrayList. What version of the product are you using? On what operating system? Powermock 1.5.5 on Windows 8.1 with Java 8

Attachment: mockTest.zip

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

@johanhaleby
Copy link
Collaborator Author

From BinisBe...@gmail.com on September 19, 2014 01:02:46

Its fixed with 1.5.6

@Am1rr3zA
Copy link

Am1rr3zA commented Dec 16, 2016

Have the same issue with List, When I am trying to mock below code it gave me the exception. if I change it to ArrayList it works.

    @Mock
    private List<Map<String, Object>> records;

I am using :

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.10.19</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-core</artifactId>
        <version>1.6.6</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-junit4</artifactId>
        <version>1.6.6</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-api-mockito</artifactId>
        <version>1.6.6</version>
        <scope>test</scope>

P.S.: Something weird about it is that when I Mock List in debugger mode I can see the size but when I want to run that line I get the expiation.

if (rawRecords.size() > topicConfig.getInt("maximum.batch.size")) {
....
}

In debugger I can see the rawRecords.size() is 2 and topicConfig.getInt("maximum.batch.size") is one and also the expression rawRecords.size() > topicConfig.getInt("maximum.batch.size") is true but when I want to step over this line I get the exception.

@RunWith(PowerMockRunner.class)
@PrepareForTest({KafkaService.class, ConfigFactory.class, Config.class})
public class KafkaServiceTest {

@Test
    public void recordSizeGreaterThanAllowedBatchSize() throws Exception {

        PowerMockito.doReturn(2).when(records, "size");

        when(topicConfig.getInt("maximum.batch.size")).thenReturn(1);
        ......
}
}

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