Skip to content

Instantly share code, notes, and snippets.

@FishOfPrey
Created June 21, 2018 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FishOfPrey/fdf33076e404ebc878b683f6383c67fc to your computer and use it in GitHub Desktop.
Save FishOfPrey/fdf33076e404ebc878b683f6383c67fc to your computer and use it in GitHub Desktop.
public class FishOfPreySettingsMockProvider implements System.StubProvider {
private FishOfPrey_Settings__c testingSettings;
public Object handleMethodCall(Object stubbedObject, String stubbedMethodName,
Type returnType, List<Type> listOfParamTypes, List<String> listOfParamNames,
List<Object> listOfArgs) {
string methodName = 'FishOfPreySettingsMockProvider.handleMethodCall() - ';
// You can use the method name and return type to determine which method was called.
System.debug(LoggingLevel.Debug, methodName + 'Name of stubbed method: ' + stubbedMethodName +
'\nReturn type of stubbed method: ' + returnType.getName() +
'\n number of parameters passed into the mocked call: ' + listOfArgs.size() +
'\n parameter(s) sent into the mocked call: ' + listOfArgs);
if(stubbedMethodName == 'getFishOfPreyCustomSettings') {
if(testingSettings == null) {
testingSettings = new FishOfPrey_Settings__c();
}
return testingSettings;
} else if (stubbedMethodName == 'setFishOfPreyCustomSettings') {
System.debug(methodName + ' ignoring call to ' + stubbedMethodName);
return null;
} else if (stubbedMethodName == 'upsertSettingsChange') {
System.debug(methodName + ' ignoring call to ' + stubbedMethodName);
return null;
}
System.assert(false, methodName + 'unmocked stubbedMethodName: ' + stubbedMethodName);
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment