我一直在尝试使用 Mockito 来模拟带有可变参数的方法:
interface A {
B b(int x, int y, C... c);
}
A a = mock(A.class);
B b = mock(B.class);
when(a.b(anyInt(), anyInt(), any(C[].class))).thenReturn(b);
assertEquals(b, a.b(1, 2));
这不起作用,但是如果我这样做:
when(a.b(anyInt(), anyInt())).thenReturn(b);
assertEquals(b, a.b(1, 2));
尽管我在对方法进行存根时完全省略了 varargs 参数,但这仍然有效。
有什么线索吗?