I am trying to write a unit test for a trigger handler method that enqueues a queueable class. I am using ApexMocks to write the unit test for this trigger method. https://github.com/financialforcedev/fflib-apex-mocks
For example , my class looks like this:
public with sharing class DividingLogic implements Queueable {
public String recId;
public DividingLogic(String recId){
}
public void execute(QueueableContext recId){
// calls a static method of another class
}
}
I know that Queueable
and QueueableContext
both are interfaces that are part of Salesforce and I think I can use them in generating ApexMocks
class. So I got started with below testing. I am trying to test if the DividingLogic
class gets called once from the trigger method. I plan to check that using mock.verify()
method.
public void testmethod afterInsertTest(){
// Given
fflib_ApexMocks mocks = new fflib_ApexMocks();
Queueable mockQueue = (Queueable)mocks.mock(DividingLogic.class);
// When
// I am wondering how would I pass the QueueableContext here
// How do I call the execute() method of Queueable
// Then
// I want to check whether the class was enqueued from the trigger
// or called at only 1 time from the trigger.
// ((Queueable)mocks.verify(mockQueue,1).execute(); ??
}
appreciate any insights and suggestions?