Skip to content

Instantly share code, notes, and snippets.

@xenogew
Created February 25, 2016 07:58
Show Gist options
  • Save xenogew/fe4d19a4c8355d87639d to your computer and use it in GitHub Desktop.
Save xenogew/fe4d19a4c8355d87639d to your computer and use it in GitHub Desktop.
How to stub a method that have variable arguments
package blah.blah.blah;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import com.amos.digital.lounge.web.controller.Foo;
@RunWith(MockitoJUnitRunner.class)
public class FooTest {
@Mock
Foo foo = new Foo();
String[] strings;
@Test
public void Bar_Blah_Blah() {
int blah = foo.bar(2, "cat", "rat", "fox", "oct");
assertTrue(blah == 99);
}
@Before
public void setup() {
when(foo.bar(anyInt(), Matchers.<String> anyVararg())).thenReturn(99);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment