Apex Mocks Snippets
This is an extension to make it easier to develop with Apex mocks by providing useful code snippets.
https://github.com/apex-enterprise-patterns/fflib-apex-mocks
Snippets
Where there are blanks - the snippet will default the cursor to populate the blank.
If there are multiple blanks, after populating the first one, pressing tab will take the cursor to
the next slot.
![Apex Mocks Example](https://github.com/B1naryVision/apex-mocks-snippets/raw/HEAD/apex-mocks-example.gif)
APEX_MOCKS is provided as a default name for the Mock Builder but will be highlighted by default
and will be overridable immediately.
unit-test
@IsTest(isParallel=true)
class Filename {
@IsTest
public static void methodUnderTest_changes_expectedResult() {
Test.startTest();
Test.stopTest();
}
}
test-case
@isTest
public static void methodUnderTest_changes_expectedResult() {
Test.startTest();
Test.stopTest();
}
answer
private with sharing class Answer implements fflib_Answer {
public Answer() {}
public Object answer(fflib_InvocationOnMock invocation) {
ArgumentType argumentOne = (ArgumentType) invocation.getArgument(0);
return null;
}
}
asserte
Assert.areEqual(, , );
asserti
Assert.isInstanceOfType(, .class, );
assertn
Assert.isNull(, );
assert
Assert.isTrue(, );
fflib-asserte
fflib_System.assertEquals(fflib_Match.(), ,);
startStubbing
APEX_MOCKS.startStubbing();
APEX_MOCKS.stopStubbing();
startTest
Test.startTest();
Test.stopTest();
create-mock-builder
fflib_ApexMocks APEX_MOCKS = new fflib_ApexMocks();
argumentCaptor
fflib_ArgumentCaptor serviceParmsCaptor = fflib_ArgumentCaptor.forClass(
.class
);
capture-argument
(Type) .capture()
verify-calls
((Service) APEX_MOCKS.verify(serviceToMock, 1)).methodName((ArgumentType) fflib_Match.anyObject());
create-mock
mockService = () APEX_MOCKS.mock(.class)
doThrowWhen
((ServiceType) APEX_MOCKS.doThrowWhen(
new TestException('Splat!'),
mockService
))
.methodName((ArgumentType) fflib_Match.anyObject());
thenReturn
APEX_MOCKS.when(
mockService.methodName((ArgumentType) fflib_Match.anyObject())
)
.thenReturn(mockResult);
thenAnswer
APEX_MOCKS.when(
mockService.methodName((ArgumentType) fflib_Match.anyObject())
)
.thenAnswer(answerInstance);
runAs
System.runAs() {
}