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