private object returnValue(fflib_InvocationOnMock invocation) { fflib_MethodReturnValue methodReturnValue = getMethodReturnValue(invocation); if (methodReturnValue != null) { if (methodReturnValue.Answer == null) { throw new fflib_ApexMocks.ApexMocksException("The stubbing is not correct, no return values have been set."); } object returnedValue = methodReturnValue.Answer.answer(invocation); if (returnedValue == null) { return(null); } if (returnedValue is Exception) { throw ((Exception)returnedValue); } return(returnedValue); } return(null); }
/** * Mock a non-void method. Called by generated mock instance classes, not directly by a developers * code. * @param mockInstance The mock object instance. * @param methodName The method for which to prepare a return value. * @param methodArgTypes The method argument types for which to prepare a return value. * @param methodArgValues The method argument values for which to prepare a return value. */ public object mockNonVoidMethod(object mockInstance, string methodName, List <Type> methodArgTypes, List <object> methodArgValues) { fflib_QualifiedMethod qm = new fflib_QualifiedMethod(extractTypeName(mockInstance), methodName, methodArgTypes, mockInstance); fflib_MethodArgValues argValues = new fflib_MethodArgValues(methodArgValues); fflib_InvocationOnMock invocation = new fflib_InvocationOnMock(qm, argValues, mockInstance); if (Verifying) { verifyMethodCall(invocation); } else if (Stubbing) { fflib_MethodReturnValue methotReturnValue = prepareMethodReturnValue(invocation); if (DoThrowWhenExceptions != null) { methotReturnValue.thenThrowMulti(DoThrowWhenExceptions); DoThrowWhenExceptions = null; return(null); } if (this.myAnswer != null) { methotReturnValue.thenAnswer(this.myAnswer); this.myAnswer = null; return(null); } return(null); } else { recordMethod(invocation); return(returnValue(invocation)); } return(null); }