@Override public void validateFor(InvocationOnMock invocation) { InvocationInfo invocationInfo = new InvocationInfo(invocation); if (invocationInfo.isVoid()) { throw cannotStubVoidMethodWithAReturnValue(invocationInfo.getMethodName()); } if (returnsNull() && invocationInfo.returnsPrimitive()) { throw wrongTypeOfReturnValue(invocationInfo.printMethodReturnType(), "null", invocationInfo.getMethodName()); } if (!returnsNull() && !invocationInfo.isValidReturnType(returnType())) { throw wrongTypeOfReturnValue(invocationInfo.printMethodReturnType(), printReturnType(), invocationInfo.getMethodName()); } }
private void validateReturnValue(Returns answer, MethodInfo methodInfo) { if (methodInfo.isVoid()) { reporter.cannotStubVoidMethodWithAReturnValue(methodInfo.getMethodName()); } if (answer.returnsNull() && methodInfo.returnsPrimitive()) { reporter.wrongTypeOfReturnValue(methodInfo.printMethodReturnType(), "null", methodInfo.getMethodName()); } if (!answer.returnsNull() && !methodInfo.isValidReturnType(answer.getReturnType())) { reporter.wrongTypeOfReturnValue(methodInfo.printMethodReturnType(), answer.printReturnType(), methodInfo.getMethodName()); } }
private void validateReturnValue(Returns answer, Invocation invocation) { if (invocation.isVoid()) { reporter.cannotStubVoidMethodWithAReturnValue(invocation.getMethod().getName()); } if (answer.returnsNull() && invocation.returnsPrimitive()) { reporter.wrongTypeOfReturnValue(invocation.printMethodReturnType(), "null", invocation.getMethodName()); } if (!answer.returnsNull() && !invocation.isValidReturnType(answer.getReturnType())) { reporter.wrongTypeOfReturnValue(invocation.printMethodReturnType(), answer.printReturnType(), invocation.getMethodName()); } }