【发布时间】:2015-12-15 15:58:33
【问题描述】:
我正在编写一个单元测试,我在其中对各种类进行存根,并且在某个阶段我需要返回 Set 的一个实例作为值。如何创建实例并在其中插入值。以下是我尝试过的编译错误
private Set<?> keys;
String[] keys1 = new String[2];
keys1[0] = "filter1";
keys1[1] = "filter2";
keys = new HashSet<>(Arrays.asList(keys1));
when(ctx.getFilter()).thenReturn(keys);
【问题讨论】:
-
getFIlter()的返回类型是什么,你得到的编译错误是什么? -
下面是编译错误:java.lang.Error: Unresolved compiler problem: The method thenReturn(Set
) in the type OngoingStubbing > 不适用于参数 (Set )
标签: java unit-testing set mockito stubbing