-
Notifications
You must be signed in to change notification settings - Fork 13
MockedMethod
APIVERSION: 58
STATUS: ACTIVE
Represents a method call that is mocked as part of a Stub object. This class is marked
IsTest , as the object and it's methods are not useful outside of a Test context. This file contains not only the MockedMethod class, but an inner Builder class. It is expected most developers will utilize the Builder class to construct instances of MockedMethod.
Constructor requiring a method signature. This is used to prevent constructing MockedMethods without a signature.
Param | Description |
---|---|
methodSignature |
We need this to define the shape of the method being mocked. |
TESTVISIBLE
TESTVISIBLE
Every MockedMethod has a methodSignature defining it's 'signature' or combination of name, parameter names and parameter types.
This method is invoked by it's parent stub object, and is responsible for returning the mocked value.
Type | Description |
---|---|
Object | Object |
SUPPRESSWARNINGS
If this MockedMethod has not been called cause a failing assertion.
Allows developers to define expected input parameters at execution time. This enables developers to mock the same method call N number of times, with different input parameters.
Param | Description |
---|---|
args |
A list of Objects that you want to this MockedMethod to to respond to. These objects must exactly match what your code invokes in order for your stub to return the specified mock output. |
Type | Description |
---|---|
MockedMethod | MockedMethod |
Sets this MockedMethod's return value. This is the value that will be returned by this mocked method when the stub calls a method that has an identical name, signature and input paramter list.
Param | Description |
---|---|
returnValue |
This is the object you want returned. |
Type | Description |
---|---|
MockedMethod | MockedMethod |
Use this variant of returning when you want the mocked method to return a list of sObjects (generic) with a specific set of IDs
Param | Description |
---|---|
incomingIds |
A list of ID's. Note, they don't have to be ids of the same sObject type. Order is preserved. |
Type | Description |
---|---|
MockedMethod | MockedMethod |
Use this method when you need the mocked method to throw an exception. Incredibly useful for testing exception handling! Note: This variant results in a generic StubException being thrown.
Type | Description |
---|---|
MockedMethod | MockedMethod |
Use this variant to have this mocked method return a developer-specified exception object. Useful for testing exception handling with specific exception types.
Param | Description |
---|---|
customException |
Type | Description |
---|---|
MockedMethod | MockedMethod |
public Boolean doMethodSignaturesAndParametersMatch(MethodSignature methodSignature, List<Object> runtimeParameters)
determines if the current method call matches on both a method signature level and against specified input parameters.
Param | Description |
---|---|
methodSignature |
A method signature to match against. |
runtimeParameters |
a List of objects representing the actual values - at runtime - of the method call. |
Type | Description |
---|---|
Boolean | Boolean |
Determines if the method, as brokered by the stub object is being called with an expected set of parameters. Note: I thought I could replace this with return this.methodParamsAtExecutionTime.equals(compareTo);
but this doesn't work, and to be honest, I'm still investigating why.
Param | Description |
---|---|
compareTo |
Type | Description |
---|---|
Boolean | Boolean |
Description class provides a 'builder' or fluent interface for constructing MockedMethod objects. While the end-developer can create MockedMethod objects directly, the point of this class is to provide an intuitive and easy-to-use/comprehend interface for building nuanced MockedMethod Objects.
Constructor requiring a methodSignatureBuilder object and a list of runtime arguments
Param | Description |
---|---|
methodSignatureBuilder |
|
args |
internal method used to set the parameter values of this MockedMethod instance.
Param | Description |
---|---|
parameters |
list of System.Type |
Type | Description |
---|---|
MockedMethod | MockedMethod |
convenience methodfor setting a single parameter type
Param | Description |
---|---|
parameter |
System.Type |
Type | Description |
---|---|
MockedMethod | this |
convenience methodfor setting two params
Param | Description |
---|---|
parameter |
System.Type |
parameter2 |
System.Type |
Type | Description |
---|---|
MockedMethod | this |
convenience methodfor setting three params
Param | Description |
---|---|
parameter |
System.Type |
parameter2 |
System.Type |
parameter3 |
System.Type |
Type | Description |
---|---|
MockedMethod | return description |
public MockedMethod withParameterValues(Object parameter, Object parameter2, Object parameter3, Object parameter4)
SUPPRESSWARNINGS
convenience methodfor setting four parameters
Param | Description |
---|---|
parameter |
parameter description |
parameter2 |
parameter2 description |
parameter3 |
parameter3 description |
parameter4 |
parameter4 description |
Type | Description |
---|---|
MockedMethod | this |
This variant allows developers to specify a list of IDs to be assigned to the returning sObject List
Param | Description |
---|---|
ids |
The list of Ids to assign. |
Type | Description |
---|---|
Stub | MockedMethod.Builder |
This variant allows developers to specify the object that will be returned when this mocked method is executed by its parent stub.
Param | Description |
---|---|
returnValue |
Type | Description |
---|---|
Stub | Stub.Builder |
This variant allows developers to specify a void return.
Type | Description |
---|---|
Stub | Stub.Builder |
This variant allows developers to throw an internally generated Stub.StubException object when the method is executed.
Type | Description |
---|---|
Stub | Stub.Builder |
Use this variant to have this mocked method return a developer-specified exception object. Useful for testing exception handling with specific exception types. Note: This only works for custom exceptions. Note: Developers construct your exception like this: <CustomExceptioType> customException =
new <CustomExceptionType>('message');
Param | Description |
---|---|
customException |
Type | Description |
---|---|
Stub | MockedMethod |
Responsible for returning a fully formed MockedMethod instance.
Param | Description |
---|---|
signature |
Type | Description |
---|---|
MockedMethod | MockedMethod |