SOQL Lib Mocking

mail@pastecode.io avatar
unknown
java
a year ago
915 B
5
Indexable
public with sharing class ExampleController {

    public static List<Account> getPartnerAccounts(String accountName) {
        
        // Your additional logic here 
        
        return SOQL_Account.query()
            .byRecordType('Partner')
            .byName(accountName)
            .with(Account.BillingCity, Account.BillingCountry)
            .mockId('ExampleController.getPartnerAccounts')
            .toList();
    }
}

@IsTest
private class ExampleControllerTest {

    @IsTest
    static void getPartnerAccounts() {
        List<Account> accounts = new List<Account>{
            new Account(Name = 'MyAccount 1'),
            new Account(Name = 'MyAccount 2')
        };

        SOQL.setMock('ExampleController.getPartnerAccounts', accounts);

        // Test
        List<Account> result = ExampleController.getPartnerAccounts('MyAccount');

        Assert.areEqual(accounts, result);
    }
}