Skip to content

Commit

Permalink
Merge pull request apex-enterprise-patterns#19 from OrtooApps/feature…
Browse files Browse the repository at this point in the history
…/criteria-with-date-literals

Feature/criteria with date literals
  • Loading branch information
rob-baillie-ortoo committed Feb 28, 2022
2 parents 234dc61 + fb6a7be commit 93b8eb2
Show file tree
Hide file tree
Showing 54 changed files with 1,767 additions and 235 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/create-org-and-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
# Run Apex Unit Tests

- name: Run Apex Unit Tests
run: sfdx force:apex:test:run -r human -u "${{env.ORG_ALIAS_PREFIX}}${{github.run_number}}" --codecoverage --wait 20 | grep -v ' Pass '; test ${PIPESTATUS[0]} -eq 0
run: sfdx force:apex:test:run -r human -u "${{env.ORG_ALIAS_PREFIX}}${{github.run_number}}" --wait 20 | grep -v ' Pass '; test ${PIPESTATUS[0]} -eq 0

# Prepare Jest Modules

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
*/
public with sharing class fflib_Comparator
{
public interface Comparable
{
Integer compare( Object otherValue );
}

public static Boolean compareTo(Object object1, fflib_Operator operator, Object object2)
{
Expand All @@ -53,6 +57,10 @@ public with sharing class fflib_Comparator

public static Integer compare(Object object1, Object object2)
{
if ( object2 instanceOf Comparable ) {
return ((Comparable)object2).compare( object1 );
}

if (object1 == null && object2 == null)
return 0;
else if (object1 == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,16 @@ public virtual with sharing class fflib_Criteria
this.embraced = embraced;
}

/**
* Defines a 'Literal' that can be used as to compare against.
* For example, a Date Literal such as TODAY.
*
* @param embraced Braces will be added if set to TRUE
*/
public interface Literal {
String toLiteral();
}

/**
* @param value The value to convert
*
Expand All @@ -777,6 +787,11 @@ public virtual with sharing class fflib_Criteria
{
if (value == null) return 'null';

if ( value instanceOf Literal )
{
return ((Literal)value).toLiteral();
}

if (value instanceof String || value instanceof Id)
{
String manipulated = (String) value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,27 @@ private with sharing class fflib_ComparatorTest
System.assert(exceptionThrown);

}

@isTest
private static void compare_whenGivenAComparatorComparable_callsCompareAgainstThat() // NOPMD: Test method name format
{
Test.startTest();
Integer got = fflib_Comparator.compare( 'object1', new ComparableThing() );
Test.stopTest();

System.assertEquals( 0, got, 'compare, when given an instance of Comparator.Comparable in object2, will call compare against that and return the result' );
}

class ComparableThingCalledWithUnexpectedValueException extends Exception {}
class ComparableThing implements fflib_Comparator.Comparable
{
public Integer compare( Object otherValue )
{
if ( otherValue == 'object1' )
{
return 0;
}
throw new ComparableThingCalledWithUnexpectedValueException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ public inherited sharing class FrameworkErrorCodes {
public final static String CONFIGURATION_WITH_INVALID_CLASS = 'APP-00002';
public final static String CONFIGURATION_WITH_INVALID_SOBJECT_TYPE = 'APP-00003';

public final static String DML_ON_INACCESSIBLE_FIELDS = '00000';
public final static String DML_INSERT_NOT_ALLOWED = '00001';
public final static String DML_UPDATE_NOT_ALLOWED = '00002';
public final static String DML_DELETE_NOT_ALLOWED = '00003';
public final static String DML_PUBLISH_NOT_ALLOWED = '00004';
public final static String NON_EVALUATABLE_CRITERIA = 'CRI-00000';

public final static String DML_ON_INACCESSIBLE_FIELDS = '0000000';
public final static String DML_INSERT_NOT_ALLOWED = '0000001';
public final static String DML_UPDATE_NOT_ALLOWED = '0000002';
public final static String DML_DELETE_NOT_ALLOWED = '0000003';
public final static String DML_PUBLISH_NOT_ALLOWED = '0000004';

public final static String SELECTOR_UNBOUND_COUNT_QUERY = '0000000';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public with sharing class ortoo_ExceptionTest {
}
Test.stopTest();

Amoss_Asserts.assertDoesNotContain( '<init>', stackTrace, 'getStackTraceString, will return the Stack Trace based on where the exception was constructed (but not the exception constructor)' );
Amoss_Asserts.assertContains( 'ortoo_ExceptionTest.getStackTraceString_willReturnTheStackTrace', stackTrace, 'getStackTraceString, will return the Stack Trace based on where the exception was constructed' );
ortoo_Asserts.assertDoesNotContain( '<init>', stackTrace, 'getStackTraceString, will return the Stack Trace based on where the exception was constructed (but not the exception constructor)' );
ortoo_Asserts.assertContains( 'ortoo_ExceptionTest.getStackTraceString_willReturnTheStackTrace', stackTrace, 'getStackTraceString, will return the Stack Trace based on where the exception was constructed' );
}

@isTest
Expand All @@ -72,8 +72,8 @@ public with sharing class ortoo_ExceptionTest {
}
Test.stopTest();

Amoss_Asserts.assertDoesNotContain( '<init>', stackTrace, 'getStackTraceString, when the exception is subclassed, will return the Stack Trace based on where the exception was constructed (but not the exception constructor)' );
Amoss_Asserts.assertContains( 'ortoo_ExceptionTest.getStackTraceString_whenSubclassed_willReturnTheStackTrace', stackTrace, 'getStackTraceString, when the exception is subclassed, will return the Stack Trace based on where the exception was constructed' );
ortoo_Asserts.assertDoesNotContain( '<init>', stackTrace, 'getStackTraceString, when the exception is subclassed, will return the Stack Trace based on where the exception was constructed (but not the exception constructor)' );
ortoo_Asserts.assertContains( 'ortoo_ExceptionTest.getStackTraceString_whenSubclassed_willReturnTheStackTrace', stackTrace, 'getStackTraceString, when the exception is subclassed, will return the Stack Trace based on where the exception was constructed' );
}

@isTest
Expand All @@ -91,10 +91,10 @@ public with sharing class ortoo_ExceptionTest {
}
Test.stopTest();

Amoss_Asserts.assertDoesNotContain( '<init>', stackTrace, 'getStackTraceString, when construction is inside multiple layers of methods, will return the Stack Trace based on where the exception was raised - with each level (not the exception constructor)' );
Amoss_Asserts.assertContains( 'ortoo_ExceptionTest.throwAnOrtooExceptionInnerMethodCall', stackTrace, 'getStackTraceString, when construction is inside multiple layers of methods, will return the Stack Trace based on where the exception was raised - with each level (method 1)' );
Amoss_Asserts.assertContains( 'ortoo_ExceptionTest.throwAnOrtooException', stackTrace, 'getStackTraceString, when construction is inside multiple layers of methods, will return the Stack Trace based on where the exception was raised - with each level (method 2)' );
Amoss_Asserts.assertContains( 'ortoo_ExceptionTest.getStackTraceString_whenBuiltInsideLayers_willReturnTheStackTrace', stackTrace, 'getStackTraceString, when construction is inside multiple layers of methods, will return the Stack Trace based on where the exception was raised - with each level (method 3)' );
ortoo_Asserts.assertDoesNotContain( '<init>', stackTrace, 'getStackTraceString, when construction is inside multiple layers of methods, will return the Stack Trace based on where the exception was raised - with each level (not the exception constructor)' );
ortoo_Asserts.assertContains( 'ortoo_ExceptionTest.throwAnOrtooExceptionInnerMethodCall', stackTrace, 'getStackTraceString, when construction is inside multiple layers of methods, will return the Stack Trace based on where the exception was raised - with each level (method 1)' );
ortoo_Asserts.assertContains( 'ortoo_ExceptionTest.throwAnOrtooException', stackTrace, 'getStackTraceString, when construction is inside multiple layers of methods, will return the Stack Trace based on where the exception was raised - with each level (method 2)' );
ortoo_Asserts.assertContains( 'ortoo_ExceptionTest.getStackTraceString_whenBuiltInsideLayers_willReturnTheStackTrace', stackTrace, 'getStackTraceString, when construction is inside multiple layers of methods, will return the Stack Trace based on where the exception was raised - with each level (method 3)' );
}

@isTest
Expand All @@ -112,10 +112,10 @@ public with sharing class ortoo_ExceptionTest {
}
Test.stopTest();

Amoss_Asserts.assertDoesNotContain( '<init>', stackTrace, 'getStackTraceString, when the exception is subclassed and there are multiple layers of methods, will return the Stack Trace based on where the exception was raised - with each level (not the exception constructor)' );
Amoss_Asserts.assertContains( 'ortoo_ExceptionTest.throwASubclassedExceptionInnerMethodCall', stackTrace, 'getStackTraceString, when the exception is subclassed and there are multiple layers of methods, will return the Stack Trace based on where the exception was raised - with each level (method 1)' );
Amoss_Asserts.assertContains( 'ortoo_ExceptionTest.throwASubclassedException', stackTrace, 'getStackTraceString, when the exception is subclassed and when construction is inside multiple layers of methods, will return the Stack Trace based on where the exception was raised - with each level (method 2)' );
Amoss_Asserts.assertContains( 'ortoo_ExceptionTest.getStackTraceString_whenSubclassedAndMultipleMethods_willReturnTheStackTrace', stackTrace, 'getStackTraceString, when the exception is subclassed and there are multiple layers of methods, will return the Stack Trace based on where the exception was raised - with each level (method 3)' );
ortoo_Asserts.assertDoesNotContain( '<init>', stackTrace, 'getStackTraceString, when the exception is subclassed and there are multiple layers of methods, will return the Stack Trace based on where the exception was raised - with each level (not the exception constructor)' );
ortoo_Asserts.assertContains( 'ortoo_ExceptionTest.throwASubclassedExceptionInnerMethodCall', stackTrace, 'getStackTraceString, when the exception is subclassed and there are multiple layers of methods, will return the Stack Trace based on where the exception was raised - with each level (method 1)' );
ortoo_Asserts.assertContains( 'ortoo_ExceptionTest.throwASubclassedException', stackTrace, 'getStackTraceString, when the exception is subclassed and when construction is inside multiple layers of methods, will return the Stack Trace based on where the exception was raised - with each level (method 2)' );
ortoo_Asserts.assertContains( 'ortoo_ExceptionTest.getStackTraceString_whenSubclassedAndMultipleMethods_willReturnTheStackTrace', stackTrace, 'getStackTraceString, when the exception is subclassed and there are multiple layers of methods, will return the Stack Trace based on where the exception was raised - with each level (method 3)' );
}

@isTest
Expand All @@ -134,10 +134,10 @@ public with sharing class ortoo_ExceptionTest {
}
Test.stopTest();

Amoss_Asserts.assertDoesNotContain( '<init>', stackTrace, 'regenerateStackTraceString, when called, will create a new stack trace from the given point' );
Amoss_Asserts.assertDoesNotContain( 'ortoo_ExceptionTest.throwASubclassedExceptionInnerMethodCall', stackTrace, 'regenerateStackTraceString, when called, will create a new stack trace from the given point (method 1)' );
Amoss_Asserts.assertDoesNotContain( 'ortoo_ExceptionTest.throwASubclassedException', stackTrace, 'regenerateStackTraceString, when called, will create a new stack trace from the given point (method 2)' );
Amoss_Asserts.assertContains( 'ortoo_ExceptionTest.regenerateStackTraceString_willCreateANewStackTraceFromTheGivenPoint', stackTrace, 'regenerateStackTraceString, when called, will create a new stack trace from the given point (actual spot called)' );
ortoo_Asserts.assertDoesNotContain( '<init>', stackTrace, 'regenerateStackTraceString, when called, will create a new stack trace from the given point' );
ortoo_Asserts.assertDoesNotContain( 'ortoo_ExceptionTest.throwASubclassedExceptionInnerMethodCall', stackTrace, 'regenerateStackTraceString, when called, will create a new stack trace from the given point (method 1)' );
ortoo_Asserts.assertDoesNotContain( 'ortoo_ExceptionTest.throwASubclassedException', stackTrace, 'regenerateStackTraceString, when called, will create a new stack trace from the given point (method 2)' );
ortoo_Asserts.assertContains( 'ortoo_ExceptionTest.regenerateStackTraceString_willCreateANewStackTraceFromTheGivenPoint', stackTrace, 'regenerateStackTraceString, when called, will create a new stack trace from the given point (actual spot called)' );
}

@isTest
Expand All @@ -157,9 +157,9 @@ public with sharing class ortoo_ExceptionTest {
}
Test.stopTest();

Amoss_Asserts.assertDoesNotContain( 'ortoo_ExceptionTest.throwASubclassedExceptionInnerMethodCall', stackTrace, 'regenerateStackTraceString, when called with a number of levels to skipp, will create a new stack trace from the given point, skipping the specified number of levels (1st level is skipped)' );
Amoss_Asserts.assertContains( 'ortoo_ExceptionTest.throwASubclassedException', stackTrace, 'regenerateStackTraceString, when called with a number of levels to skipp, will create a new stack trace from the given point, skipping the specified number of levels (2nd level is not skipped)' );
Amoss_Asserts.assertContains( 'ortoo_ExceptionTest.regenerateStackTraceString_whenPassedANumber_willCreateANewStackTraceWithLevelsSkipped', stackTrace, 'regenerateStackTraceString, when called with a number of levels to skipp, will create a new stack trace from the given point, skipping the specified number of levels (3rd level is not skipped)' );
ortoo_Asserts.assertDoesNotContain( 'ortoo_ExceptionTest.throwASubclassedExceptionInnerMethodCall', stackTrace, 'regenerateStackTraceString, when called with a number of levels to skipp, will create a new stack trace from the given point, skipping the specified number of levels (1st level is skipped)' );
ortoo_Asserts.assertContains( 'ortoo_ExceptionTest.throwASubclassedException', stackTrace, 'regenerateStackTraceString, when called with a number of levels to skipp, will create a new stack trace from the given point, skipping the specified number of levels (2nd level is not skipped)' );
ortoo_Asserts.assertContains( 'ortoo_ExceptionTest.regenerateStackTraceString_whenPassedANumber_willCreateANewStackTraceWithLevelsSkipped', stackTrace, 'regenerateStackTraceString, when called with a number of levels to skipp, will create a new stack trace from the given point, skipping the specified number of levels (3rd level is not skipped)' );
}

@isTest
Expand Down
Loading

0 comments on commit 93b8eb2

Please sign in to comment.