1 /* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 package org.mockito.internal.stubbing.defaultanswers; 6 7 import org.mockito.invocation.InvocationOnMock; 8 import org.mockito.stubbing.Answer; 9 10 import java.io.Serializable; 11 import java.lang.reflect.Method; 12 13 /** 14 * Internal answer to forward invocations on a real instance. 15 * 16 * @since 1.9.5 17 */ 18 public class ForwardsInvocations implements Answer<Object>, Serializable { 19 20 private static final long serialVersionUID = -8343690268123254910L; 21 22 private Object delegatedObject = null ; 23 24 public ForwardsInvocations(Object delegatedObject) { 25 this.delegatedObject = delegatedObject ; 26 } 27 28 public Object answer(InvocationOnMock invocation) throws Throwable { 29 Method method = invocation.getMethod() ; 30 31 return method.invoke(delegatedObject, invocation.getArguments()); 32 } 33 }