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); }
public object answer(fflib_InvocationOnMock invocation) { actualInvocation = invocation; List<object> emptyList = invocation.getArguments(); System.assertEquals(0, emptyList.size(), "the argument list from a method without arguments should be empty"); return null; }
public object answer(fflib_InvocationOnMock invocation) { actualInvocation = invocation; string argument = (string)invocation.getArgument(1); System.assertNotEquals(null, argument, " the argument should have some value"); argument = argument.replace("Hi", "Bye"); return argument; }
public object answer(fflib_InvocationOnMock invocation) { actualInvocation = invocation; try { object noExistingObj = invocation.getArgument(-1); System.assert(false, "an exception was expected because the argument index cannot be negative"); } catch (fflib_ApexMocks.ApexMocksException exp) { string expectedMessage = "Invalid index, must be greater or equal to zero and less of 2."; string actualMessage = exp.getMessage(); System.assertEquals(expectedMessage, actualMessage, "the message return by the exception is not as expected"); } 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); }
public object answer(fflib_InvocationOnMock invocation) { actualInvocation = invocation; this.answerMessage = "and this is the second one"; return answerMessage; }
public object answer(fflib_InvocationOnMock invocation) { actualInvocation = invocation; this.answerMessage = "this is the first answer"; return answerMessage; }
public object answer(fflib_InvocationOnMock invocation) { actualInvocation = invocation; throw new fflib_ApexMocks.ApexMocksException("an error occurs on the execution of the answer"); return null; }
public object answer(fflib_InvocationOnMock invocation) { actualInvocation = invocation; return null; }
/** * Get the method return value for the given method call. * @param mockInvocation The invocation on the mock containing information about the method and the arguments. * @return The MethodReturnValue instance. */ public fflib_MethodReturnValue getMethodReturnValue(fflib_InvocationOnMock mockInvocation) { return(methodReturnValueRecorder.getMethodReturnValue(mockInvocation)); }
/** * Record a method was called on a mock object. * @param mockInvocation The invocation on the mock containing information about the method and the arguments. */ public void recordMethod(fflib_InvocationOnMock mockInvocation) { methodCountRecorder.recordMethod(mockInvocation); }
/** * Verfiy a method was called on a mock object. * @param mockInvocation The invocation on the mock containing information about the method and the arguments. */ public void verifyMethodCall(fflib_InvocationOnMock mockInvocation) { this.methodVerifier.verifyMethodCall(mockInvocation, verificationMode); this.methodVerifier = new fflib_AnyOrder(); Verifying = false; }