Created
February 25, 2016 07:58
-
-
Save xenogew/fe4d19a4c8355d87639d to your computer and use it in GitHub Desktop.
How to stub a method that have variable arguments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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