Newer Version Available
StubProvider Interface
Namespace
Usage
The StubProvider interface allows you to define the behavior of a stubbed Apex class. The interface specifies a single method that requires implementing: handleMethodCall(). You specify the behavior of each method of the stubbed class in the handleMethodCall() method.
In your Apex test, you create a stubbed object using the Test.createStub() method. When you invoke methods on the stubbed object, StubProvider.handleMethodCall() is called, which performs the behavior that you’ve specified for each method.
StubProvider Methods
The following are methods for StubProvider.
handleMethodCall(stubbedObject, stubbedMethodName, returnType, listOfParamTypes, listOfParamNames, listOfArgs)
Signature
public Object handleMethodCall(Object stubbedObject, String stubbedMethodName, System.Type returnType, List<System.Type> listOfParamTypes, List<String> listOfParamNames, List<Object> var6)
Parameters
- stubbedObject
- Type: Object
- The stubbed object.
- stubbedMethodName
- Type: String
- The name of the invoked method.
- returnType
- Type: System.Type
- The return type of the invoked method.
- listOfParamTypes
- Type: List<System.Type>
- A list of the parameter types of the invoked method.
- listOfParamNames
- Type: List<String>
- A list of the parameter names of the invoked method.
- listOfArgs
- Type: List<Object>
- The actual argument values passed into this method at runtime.
Return Value
Type: Object
Usage
You can use the parameters passed into this method to identify which method on the stubbed object was invoked. Then you can define the behavior for each identified method.