/* * Method that validate the verification mode used in the verify. * Not all the methods from the fflib_VerificationMode are implemented for the different classes that extends the fflib_MethodVerifier. * The error is thrown at run time, so this method is called in the method that actually performs the verify. * @param verificationMode The verification mode that have to been verified. * @throws Exception with message for the fflib_VerificationMode not implemented. */ protected override void validateMode(fflib_VerificationMode verificationMode) { if (verificationMode.Method == fflib_VerificationMode.ModeName.CALLS) { throw new fflib_ApexMocks.ApexMocksException("The calls() method is available only in the InOrder Verification."); } }
/** * Construct an ApexMocks instance. */ public fflib_ApexMocks() { Verifying = false; this.methodCountRecorder = new fflib_MethodCountRecorder(); this.verificationMode = new fflib_VerificationMode(); this.methodVerifier = new fflib_AnyOrder(); this.methodReturnValueRecorder = new fflib_MethodReturnValueRecorder(); this.methodReturnValueRecorder.Stubbing = false; }
/* * Verifies a method was invoked the expected number of times, with the expected arguments. * @param qualifiedMethod The method to be verified. * @param methodArg The arguments of the method that needs to be verified. * @param verificationMode The verification mode that holds the setting about how the verification should be performed. */ protected override void verify(fflib_QualifiedMethod qm, fflib_MethodArgValues methodArg, fflib_VerificationMode verificationMode) { int methodCount = getMethodCount(qm, methodArg); string qualifier = ""; int expectedCount = null; if ((verificationMode.VerifyMin == verificationMode.VerifyMax) && methodCount != verificationMode.VerifyMin) { expectedCount = verificationMode.VerifyMin; } else if (verificationMode.VerifyMin != null && verificationMode.VerifyMin > methodCount) { expectedCount = verificationMode.VerifyMin; qualifier = " or more times"; } else if (verificationMode.VerifyMax != null && verificationMode.VerifyMax < methodCount) { expectedCount = verificationMode.VerifyMax; qualifier = " or fewer times"; } if (expectedCount != null) { throwException(qm, "", expectedCount, qualifier, methodCount, verificationMode.CustomAssertMessage); } }
/** * Verify a method was called on a mock object. * @param mockInstance The mock object instance. * @param verificationMode Defines the constraints for performing the verification (e.g. the minimum and maximum expected invocation counts). * @return The mock object instance. */ public object verify(object mockInstance, fflib_VerificationMode verificationMode) { Verifying = true; this.verificationMode = verificationMode; return(mockInstance); }