Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplification of setting mocks for Selectors and Domains #453

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

foxysolutions
Copy link
Contributor

@foxysolutions foxysolutions commented Jun 5, 2023

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

Reinier van den Assum and others added 2 commits June 5, 2023 13:34
…ories 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();
fflib.domain.setMock( m_domLeads );
* New code:
fflib.domain.setMock( Lead.SObjectType, m_domLeads );
@foxysolutions foxysolutions changed the title Feature/20230605 setMock SObjectType introduction Introducing simplification of setting mocks for Selectors and Domains Jun 5, 2023
@foxysolutions foxysolutions changed the title Introducing simplification of setting mocks for Selectors and Domains Simplification of setting mocks for Selectors and Domains Jun 5, 2023
@foxysolutions
Copy link
Contributor Author

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

@ImJohnMDaniel
Copy link
Contributor

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

@foxysolutions
Copy link
Contributor Author

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

@wimvelzeboer
Copy link
Contributor

@foxysolutions If you already want to start working with this new method, then you can also add the fflib-apex-extensions repo to your project.
The fflib_ClassicXXXFactory and the fflib_DynamicXXXFactory already have this method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants