/
VarargsAndAnyPicksUpExtraInvocationsTest.java
52 lines (42 loc) · 1.43 KB
/
VarargsAndAnyPicksUpExtraInvocationsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Copyright (c) 2007 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockitousage.bugs.varargs;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.junit.Test;
import org.mockito.Mock;
import org.mockitoutil.TestBase;
public class VarargsAndAnyPicksUpExtraInvocationsTest extends TestBase {
public interface TableBuilder {
void newRow(String trAttributes, String... cells);
}
@Mock TableBuilder table;
@Test
public void shouldVerifyCorrectlyWithAny() {
// when
table.newRow("qux", "foo", "bar", "baz");
table.newRow("abc", "def");
// then
verify(table, times(2)).newRow(anyString(), (String[]) any());
}
@Test
public void shouldVerifyCorrectlyNumberOfInvocationsUsingAnyAndEqualArgument() {
// when
table.newRow("x", "foo", "bar", "baz");
table.newRow("x", "def");
// then
verify(table, times(2)).newRow(eq("x"), (String[]) any());
}
@Test
public void shouldVerifyCorrectlyNumberOfInvocationsWithVarargs() {
// when
table.newRow("qux", "foo", "bar", "baz");
table.newRow("abc", "def");
// then
verify(table).newRow(anyString(), eq("foo"), anyString(), anyString());
verify(table).newRow(anyString(), anyString());
}
}