fflib-apex-common icon indicating copy to clipboard operation
fflib-apex-common copied to clipboard

Simplification of setting mocks for Selectors and Domains

Open foxysolutions opened this issue 2 years ago • 4 comments
trafficstars

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 );

This change is Reviewable

foxysolutions avatar Jun 05 '23 15:06 foxysolutions

@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 avatar Jun 21 '23 08:06 foxysolutions

@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.

ImJohnMDaniel avatar Jun 21 '23 16:06 ImJohnMDaniel

@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!

foxysolutions avatar Jan 22 '24 12:01 foxysolutions