No methods matching the name(s) stream in hierarchy of class java.util.Arrays$ArrayList

早过忘川 提交于 2019-12-23 05:27:37

问题


So I am using java 8 and trying to write some tests with PowerMock and Mockito. I am getting a MethodNotFoundException with the message:

No methods matching the name(s) stream were found in the class hierarchy of class java.util.Arrays$ArrayList.

I double checked the ArrayList documentation and it definitely looks like it inherits stream from Collections. Is this a problem with PowerMockito or am I missing something?

Line in question

PowerMockito.when(thing.call("services", "things")).thenReturn(Arrays.asList("testService")); // Doesn't matter if it's new ArrayList<String>()));

Then has something like this called on it

services.stream().filter( x -> //filter).collect(Collectors.toList())

EDIT: After further research this appears to be a PowerMock Problem. Would love a solution.


回答1:


This appeared to be a bug in PowerMock 1.5.5 and has been solved in 1.5.6

Reference: https://github.com/jayway/powermock/issues/536




回答2:


java.util.Arrays$ArrayList is an inner class of java.util.Arrays returned by Arrays.asList(), and is not the same as java.util.ArrayList.

If the stream() method can't be found, it might be because java.util.Arrays$ArrayList is private?



来源:https://stackoverflow.com/questions/33369870/no-methods-matching-the-names-stream-in-hierarchy-of-class-java-util-arraysar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!