Skip to content

Commit

Permalink
Removed external dependencies from the fflib extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-baillie-ortoo committed May 4, 2022
1 parent 1b3ba7b commit 1a7964e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 41 deletions.
6 changes: 1 addition & 5 deletions sfdx-source/apex-common/main/classes/fflib_Application.cls
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,7 @@ public virtual class fflib_Application
}

try {
if ( !serviceInterfaceName.endsWith( 'ILoggerService' ) )
{
LoggerService.log( LoggerService.LEVEL.INFO, 'Using default implementation ' + defaultServiceName + ' for ' + serviceInterfaceName );
}

System.debug( LoggingLevel.INFO, 'Using default implementation ' + defaultServiceName + ' for ' + serviceInterfaceName );
return defaultServiceType.newInstance();
}
catch ( Exception e ) {
Expand Down
4 changes: 2 additions & 2 deletions sfdx-source/apex-common/main/classes/fflib_QueryFactory.cls
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
}
set;
}
private ISearchCriteria conditionCriteria;
private fflib_ISoqlable conditionCriteria;
private Integer limitCount;
private Integer offsetCount;
private List<Ordering> order;
Expand Down Expand Up @@ -347,7 +347,7 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
/**
* @param conditionExpression Sets the WHERE clause to the string provided by the given ISearchCriteria
**/
public fflib_QueryFactory setCondition(ISearchCriteria criteria){
public fflib_QueryFactory setCondition(fflib_ISoqlable criteria){
this.conditionCriteria = criteria;
this.conditionExpression = null;
return this;
Expand Down
73 changes: 41 additions & 32 deletions sfdx-source/apex-common/test/classes/fflib_QueryFactoryTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -72,56 +72,61 @@ private class fflib_QueryFactoryTest {
}

@isTest
static void iSearchCriteriaCondition(){
static void iSoqlableCondition(){

String whereClause = 'name = \'test\'';

Amoss_Instance searchCriteriaController = new Amoss_Instance( ISearchCriteria.class );
searchCriteriaController
.when( 'toSoql' )
.returns( whereClause );
fflib_ApexMocks mocks = new fflib_ApexMocks();
fflib_ISoqlable mockSoqlable = (fflib_ISoqlable)mocks.mock( fflib_ISoqlable.class );

mocks.startStubbing();
mocks.when( mockSoqlable.toSOQL() ).thenReturn( whereClause );
mocks.stopStubbing();

fflib_QueryFactory qf = new fflib_QueryFactory(Contact.SObjectType);
qf.selectField('name');
qf.setCondition( (ISearchCriteria)searchCriteriaController.getDouble() );
qf.setCondition( mockSoqlable );

System.assertEquals( whereClause, qf.getCondition(), 'setCondition, when given an ISearchCriteria, will set the condition based on the criteria' );
System.assertEquals( whereClause, qf.getCondition(), 'setCondition, when given an fflib_ISoqlable, will set the condition based on the criteria' );

String query = qf.toSOQL();
System.assert( query.endsWith('WHERE name = \'test\''),'Query should have ended with a filter on name, got: '+query);

((fflib_ISoqlable)mocks.verify( mockSoqlable, mocks.atLeast(1))).toSoql();
}

@isTest
static void iSearchCriteriaCondition_notEvaluatedOnSet(){
static void iSoqlableCondition_notEvaluatedOnSet(){

Amoss_Instance searchCriteriaController = new Amoss_Instance( ISearchCriteria.class );
searchCriteriaController
.expectsNoCalls();
fflib_ApexMocks mocks = new fflib_ApexMocks();
fflib_ISoqlable mockSoqlable = (fflib_ISoqlable)mocks.mock( fflib_ISoqlable.class );

fflib_QueryFactory qf = new fflib_QueryFactory(Contact.SObjectType);
qf.selectField('name');
qf.setCondition( (ISearchCriteria)searchCriteriaController.getDouble() );
qf.setCondition( mockSoqlable );

searchCriteriaController.verify();
((fflib_ISoqlable)mocks.verify( mockSoqlable, mocks.never())).toSoql();
}

@isTest
static void iSearchCriteriaCondition_isEvaluatedOnGet(){
static void iSoqlableCondition_isEvaluatedOnGet(){

String whereClause = 'name = \'test\'';

Amoss_Instance searchCriteriaController = new Amoss_Instance( ISearchCriteria.class );
searchCriteriaController
.when( 'toSoql' )
.returns( whereClause );
fflib_ApexMocks mocks = new fflib_ApexMocks();
fflib_ISoqlable mockSoqlable = (fflib_ISoqlable)mocks.mock( fflib_ISoqlable.class );

mocks.startStubbing();
mocks.when( mockSoqlable.toSOQL() ).thenReturn( whereClause );
mocks.stopStubbing();

fflib_QueryFactory qf = new fflib_QueryFactory(Contact.SObjectType);
qf.selectField('name');
qf.setCondition( (ISearchCriteria)searchCriteriaController.getDouble() );
qf.setCondition( mockSoqlable );

qf.getCondition();

searchCriteriaController.verify();
((fflib_ISoqlable)mocks.verify( mockSoqlable, mocks.times(1))).toSoql();
}

@isTest
Expand All @@ -130,17 +135,19 @@ private class fflib_QueryFactoryTest {
String stringWhereClause = 'name = \'string\'';
String criteriaWhereClause = 'name = \'criteria\'';

Amoss_Instance searchCriteriaController = new Amoss_Instance( ISearchCriteria.class );
searchCriteriaController
.when( 'toSoql' )
.returns( criteriaWhereClause );
fflib_ApexMocks mocks = new fflib_ApexMocks();
fflib_ISoqlable mockSoqlable = (fflib_ISoqlable)mocks.mock( fflib_ISoqlable.class );

mocks.startStubbing();
mocks.when( mockSoqlable.toSOQL() ).thenReturn( criteriaWhereClause );
mocks.stopStubbing();

fflib_QueryFactory qf = new fflib_QueryFactory(Contact.SObjectType);
qf.selectField('name');
qf.setCondition( stringWhereClause );
qf.setCondition( (ISearchCriteria)searchCriteriaController.getDouble() );
qf.setCondition( mockSoqlable );

System.assertEquals( criteriaWhereClause, qf.getCondition(), 'setCondition, when given a string then a ISearchCriteria, will set the condition based on the last thing - the criteria' );
System.assertEquals( criteriaWhereClause, qf.getCondition(), 'setCondition, when given a string then a fflib_ISoqlable, will set the condition based on the last thing - the criteria' );
}

@isTest
Expand All @@ -149,17 +156,19 @@ private class fflib_QueryFactoryTest {
String stringWhereClause = 'name = \'string\'';
String criteriaWhereClause = 'name = \'criteria\'';

Amoss_Instance searchCriteriaController = new Amoss_Instance( ISearchCriteria.class );
searchCriteriaController
.when( 'toSoql' )
.returns( criteriaWhereClause );
fflib_ApexMocks mocks = new fflib_ApexMocks();
fflib_ISoqlable mockSoqlable = (fflib_ISoqlable)mocks.mock( fflib_ISoqlable.class );

mocks.startStubbing();
mocks.when( mockSoqlable.toSOQL() ).thenReturn( criteriaWhereClause );
mocks.stopStubbing();

fflib_QueryFactory qf = new fflib_QueryFactory(Contact.SObjectType);
qf.selectField('name');
qf.setCondition( (ISearchCriteria)searchCriteriaController.getDouble() );
qf.setCondition( mockSoqlable );
qf.setCondition( stringWhereClause );

System.assertEquals( stringWhereClause, qf.getCondition(), 'setCondition, when given a ISearchCriteria then string, will set the condition based on the last thing - the string' );
System.assertEquals( stringWhereClause, qf.getCondition(), 'setCondition, when given a fflib_ISoqlable then string, will set the condition based on the last thing - the string' );
}

@isTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,10 +864,9 @@ public virtual with sharing class fflib_Criteria
return result + ')';
}

public interface Evaluator
public interface Evaluator extends fflib_ISoqlable
{
Boolean evaluate(Object obj);
String toSOQL();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public interface fflib_ISoqlable
{
String toSOQL();
}
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>53.0</apiVersion>
<status>Active</status>
</ApexClass>

0 comments on commit 1a7964e

Please sign in to comment.