ForwardsInvocationsTest.java revision 2637d96c202372854a7c71466ddcc6e90fc4fc53
1package org.mockito.internal.stubbing.defaultanswers; 2 3import org.junit.Test; 4import org.mockitoutil.TestBase; 5 6import static junit.framework.TestCase.assertEquals; 7 8public class ForwardsInvocationsTest extends TestBase { 9 10 interface Foo { 11 int bar(String baz, Object... args); 12 } 13 14 private static final class FooImpl implements Foo { 15 @Override 16 public int bar(String baz, Object... args) { 17 return baz.length() + args.length; 18 } 19 } 20 21 @Test 22 public void should_call_method_with_varargs() throws Throwable { 23 ForwardsInvocations forwardsInvocations = new ForwardsInvocations(new FooImpl()); 24 assertEquals(4, forwardsInvocations.answer(invocationOf(Foo.class, "bar", "b", new Object[] {12, "3", 4.5}))); 25 } 26 27 @Test 28 public void should_call_method_with_empty_varargs() throws Throwable { 29 ForwardsInvocations forwardsInvocations = new ForwardsInvocations(new FooImpl()); 30 assertEquals(1, forwardsInvocations.answer(invocationOf(Foo.class, "bar", "b", new Object[] {}))); 31 } 32} 33