forked from apex-enterprise-patterns/fflib-apex-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request apex-enterprise-patterns#33 from OrtooApps/feature…
…/add-dynamic-uow Added factory methods for the Dynamic Unit of Work
- Loading branch information
Showing
8 changed files
with
168 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...ork/default/ortoo-core/default/classes/fflib-extension/ortoo_DynamicUnitOfWorkFactory.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
public inherited sharing class ortoo_DynamicUnitOfWorkFactory // NOPMD: specified a mini-namespace to differentiate from fflib versions | ||
{ | ||
private static fflib_SobjectUnitOfWork.Idml defaultIdml = new SecureDml(); | ||
protected fflib_ISObjectUnitOfWork mockUow; | ||
|
||
/** | ||
* Returns a new SObjectUnitOfWork configured with the | ||
* SObjectType list provided in the constructor, returns a Mock implementation | ||
* if set via the setMock method | ||
**/ | ||
public fflib_ISObjectUnitOfWork newInstance() | ||
{ | ||
return newInstance( defaultIdml ); | ||
} | ||
|
||
/** | ||
* Returns a new SObjectUnitOfWork configured with the | ||
* SObjectType list provided in the constructor, returns a Mock implementation | ||
* if set via the setMock method | ||
**/ | ||
public fflib_ISObjectUnitOfWork newInstance( fflib_SObjectUnitOfWork.Idml dml ) | ||
{ | ||
if ( this.mockUow != null ) | ||
{ | ||
return this.mockUow; | ||
} | ||
return new ortoo_DynamicSObjectUnitOfWork( dml ); | ||
} | ||
|
||
@TestVisible | ||
private void setMock( fflib_ISObjectUnitOfWork mockUow ) | ||
{ | ||
this.mockUow = mockUow; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...lt/ortoo-core/default/classes/fflib-extension/ortoo_DynamicUnitOfWorkFactory.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>52.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
61 changes: 61 additions & 0 deletions
61
...t/ortoo-core/default/classes/fflib-extension/tests/ortoo_DynamicUnitOfWorkFactoryTest.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
@isTest | ||
private without sharing class ortoo_DynamicUnitOfWorkFactoryTest // NOPMD: mini-namespace to distinguich from fflib version | ||
{ | ||
@isTest | ||
private static void newInstance_whenGivenNoIdml_willReturnAnInstanceWithASecureDml() // NOPMD: Test method name format | ||
{ | ||
ortoo_DynamicUnitOfWorkFactory factory = new ortoo_DynamicUnitOfWorkFactory(); | ||
ortoo_DynamicSobjectUnitOfWork uow = (ortoo_DynamicSobjectUnitOfWork)factory.newInstance(); | ||
|
||
System.assert( uow.getIdml() instanceOf SecureDml, 'newInstance, when given no dml, will create an instance with a secure dml' ); | ||
} | ||
|
||
@isTest | ||
private static void newInstance_whenGivenAnIdml_willCreateAnInstanceWithThatIdml() // NOPMD: Test method name format | ||
{ | ||
ortoo_DynamicUnitOfWorkFactory factory = new ortoo_DynamicUnitOfWorkFactory(); | ||
|
||
RegisterableIdml IDml = new RegisterableIdml(); | ||
ortoo_DynamicSobjectUnitOfWork uow = (ortoo_DynamicSobjectUnitOfWork)factory.newInstance( IDml ); | ||
|
||
System.assertEquals( IDml, uow.getIdml(), 'newInstance, when given no object order and an IDml, will create an instance with the IDml' ); | ||
} | ||
|
||
@isTest | ||
private static void setMock_whenNewInstanceIsCalledWithoutAnIdml_willReturnTheMock() // NOPMD: Test method name format | ||
{ | ||
ortoo_DynamicSobjectUnitOfWork mockUow = (ortoo_DynamicSobjectUnitOfWork)new Amoss_Instance( ortoo_DynamicSobjectUnitOfWork.class ).getDouble(); | ||
ortoo_DynamicUnitOfWorkFactory factory = new ortoo_DynamicUnitOfWorkFactory(); | ||
|
||
Test.startTest(); | ||
factory.setMock( mockUow ); | ||
ortoo_DynamicSobjectUnitOfWork returnedUow = (ortoo_DynamicSobjectUnitOfWork)factory.newInstance(); | ||
Test.stopTest(); | ||
|
||
System.assertEquals( mockUow, returnedUow, 'setMock, when new instance is called without a DML, will return the mock' ); | ||
} | ||
|
||
@isTest | ||
private static void setMock_whenNewInstanceIsCalledWithAnIdml_willReturnTheMock() // NOPMD: Test method name format | ||
{ | ||
ortoo_DynamicSobjectUnitOfWork mockUow = (ortoo_DynamicSobjectUnitOfWork)new Amoss_Instance( ortoo_DynamicSobjectUnitOfWork.class ).getDouble(); | ||
ortoo_DynamicUnitOfWorkFactory factory = new ortoo_DynamicUnitOfWorkFactory(); | ||
|
||
Test.startTest(); | ||
factory.setMock( mockUow ); | ||
RegisterableIdml IDml = new RegisterableIdml(); | ||
ortoo_DynamicSobjectUnitOfWork returnedUow = (ortoo_DynamicSobjectUnitOfWork)factory.newInstance( IDml ); | ||
Test.stopTest(); | ||
|
||
System.assertEquals( mockUow, returnedUow, 'setMock, when new instance is called without an order, will return the mock' ); | ||
} | ||
|
||
private without sharing class RegisterableIdml implements fflib_SObjectUnitOfWork.IDML | ||
{ | ||
public void dmlInsert(List<SObject> objList) {} // NOPMD: empty implementation for tests | ||
public void dmlUpdate(List<SObject> objList) {} // NOPMD: empty implementation for tests | ||
public void dmlDelete(List<SObject> objList) {} // NOPMD: empty implementation for tests | ||
public void eventPublish(List<SObject> objList) {} // NOPMD: empty implementation for tests | ||
public void emptyRecycleBin(List<SObject> objList) {} // NOPMD: empty implementation for tests | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...ore/default/classes/fflib-extension/tests/ortoo_DynamicUnitOfWorkFactoryTest.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>52.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
20 changes: 20 additions & 0 deletions
20
framework/default/ortoo-core/default/classes/tests/ApplicationMockRegistrarTest.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters