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.mockito.internal.stubbing.answers; 7 8 import org.mockito.invocation.InvocationOnMock; 9 10 import static org.mockito.internal.exceptions.Reporter.wrongTypeReturnedByDefaultAnswer; 11 12 public abstract class DefaultAnswerValidator { validateReturnValueFor(InvocationOnMock invocation, Object returnedValue)13 public static void validateReturnValueFor(InvocationOnMock invocation, Object returnedValue) throws Throwable { 14 InvocationInfo invocationInfo = new InvocationInfo(invocation); 15 if (returnedValue != null && !invocationInfo.isValidReturnType(returnedValue.getClass())) { 16 throw wrongTypeReturnedByDefaultAnswer( 17 invocation.getMock(), 18 invocationInfo.printMethodReturnType(), 19 returnedValue.getClass().getSimpleName(), 20 invocationInfo.getMethodName()); 21 } 22 } 23 } 24