如何使用Powermock和mockito返回对象数组

如何使用Powermock和mockito返回对象数组,mockito,powermock,Mockito,Powermock,我有一个返回对象数组的方法 public IConfigurationElement[]GetConfigurationElements for(字符串扩展点ID) 我不知道如何使用mockito和powermock模拟这个调用 我试过了 mockConfigurationElements=(IConfigurationElement[])Mockito.anyListOf(IConfigurationElement.class).toArray() 但是这将以ClassCastExceptio

我有一个返回对象数组的方法

public IConfigurationElement[]GetConfigurationElements for(字符串扩展点ID)

我不知道如何使用mockito和powermock模拟这个调用

我试过了

mockConfigurationElements=(IConfigurationElement[])Mockito.anyListOf(IConfigurationElement.class).toArray()

但是这将以
ClassCastException
结束,使用
Mockito
的mock(stubing)调用通过以下方式完成(例如):


anyListOf()是匹配器的用法。stubing时传递匹配器而不是实际参数,这意味着如果使用满足这些匹配器的参数调用方法,则将应用行为。

我尝试过Mockito.any()和Mockito.anyListOf().toArray();你在嘲笑期末班吗?为什么要使用PowerMock?我正在用静态函数模拟其他类。您可以做的另一件事是创建一个实际数组,并用模拟对象填充它。
Mockito.when(mockObject.getConfigurationElementsFor(Mockito.anyString()).thenReturn(new IConfigurationElement[]{})
Mockito.doReturn(new IConfigurationElement[]{}).when(mockObject).getConfigurationElementsFor(Mockito.anyString());