fflib-apex-common
fflib-apex-common copied to clipboard
Simplification of setting mocks for Selectors and Domains
2023-06-05: fflib_Application.cls: Extending Selector and Domain Factories with setMock() method which doesn't require .sObjectType() to be mocked
- Feature to allow simplifying how a Selector and/or Domain are being stubbed
- To prevent forgetting to mocks.when() the method .sObjectType(), causing unexpected and undesired test method results (especially for juniors)
- Additionally, this aligns nicely with setMock() for Services where the Interface method is provided
- New approach is 100% backward compatible with a little hint for developers as reminder to mock the sObjectType()-method
- Original code to mock a Domain class:
mocks.startStubbing();
mocks.when( m_domLeads.sObjectType() ).thenReturn( Lead.SObjectType );
mocks.stopStubbing();
Application.domain.setMock( m_domLeads );
- New code:
Application.domain.setMock( Lead.SObjectType, m_domLeads );
@ImJohnMDaniel I've updated the branch to match master again, but not sure if that was the only reason why you assigned it back to me? Thanks!
@foxysolutions -- you are all good. I routinely "assign" PRs to the person that opened it. Just waiting for reviews from other team members (who may actually be on PTO this week), so I ask for your patience.
@afawcett @ImJohnMDaniel any review possible on this small change, to simplify how mocks are being set? It was already reviewed once, so pending for 2nd one. Cheers!