• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.answers;
6 
7 import static org.mockito.internal.exceptions.Reporter.wrongTypeReturnedByDefaultAnswer;
8 
9 import org.mockito.invocation.InvocationOnMock;
10 
11 public abstract class DefaultAnswerValidator {
validateReturnValueFor(InvocationOnMock invocation, Object returnedValue)12     public static void validateReturnValueFor(InvocationOnMock invocation, Object returnedValue)
13             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