You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: framework/default/ortoo-core/default/classes/fflib-extension/caching/tests/CachedSoqlExecutorTest.cls
+156Lines changed: 156 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -497,6 +497,162 @@ private without sharing class CachedSoqlExecutorTest
497
497
logger.assertNumberOfLogCalls( 0, 'clearCacheFor against a none cache, when called by a user that does not have access to the org cache, will not create a log' );
498
498
}
499
499
500
+
@isTest
501
+
privatestaticvoidquery_maxAge_session_whenCalledTwiceWithinAge_onlyIssuesOneSoql() // NOPMD: Test method name format
TestDateTimeUtils.addToCurrentTime( 50 ); // it is now 50 seconds later
516
+
logger.clearLogHistory();
517
+
List<Sobject> secondResults=executor.query( soqlStatement, 100 ); // so this should still return the results
518
+
IntegersoqlCalls=Limits.getQueries();
519
+
Test.stopTest();
520
+
521
+
System.assertEquals( 1, soqlCalls, 'query with a maximum age on session cache, when called twice within the required age, will only issue one SOQL statement' );
522
+
System.assertEquals( originalResults, secondResults, 'query with a maximum age on session cache, when called twice within the required age, returns the same results in both calls' );
523
+
524
+
logger.assertNumberOfLogCalls( 0, 'query with a maximum age on session cache,when called twice within the required age, does not generate a log entry' );
525
+
}
526
+
527
+
@isTest
528
+
privatestaticvoidquery_maxAge_session_whenCalledTwiceOutsideAge_issuesTwoSoql() // NOPMD: Test method name format
TestDateTimeUtils.addToCurrentTime( 100 ); // it is now 50 seconds later
543
+
logger.clearLogHistory();
544
+
List<Sobject> secondResults=executor.query( soqlStatement, 50 ); // so this should result in a new query because the previous results are too old
545
+
IntegersoqlCalls=Limits.getQueries();
546
+
Test.stopTest();
547
+
548
+
System.assertEquals( 2, soqlCalls, 'query with a maximum age on session cache, when called twice with the second outside the required age, will issue two SOQL statements' );
549
+
}
550
+
551
+
@isTest
552
+
privatestaticvoidquery_whenPassedANullMaxAge_throwsAnException() // NOPMD: Test method name format
ortoo_Asserts.assertContains( 'query called with a null maximumAgeInSeconds', exceptionMessage, 'query, when passed a null maximumAgeInSeconds, will throw an exception' );
572
+
}
573
+
574
+
@isTest
575
+
privatestaticvoidquery_minDate_session_whenCalledTwiceWithinDate_onlyIssuesOneSoql() // NOPMD: Test method name format
List<Sobject> secondResults=executor.query( soqlStatement, earliestDate ); // this date is earlier than the first query ran, so the cache should be used
596
+
IntegersoqlCalls=Limits.getQueries();
597
+
Test.stopTest();
598
+
599
+
System.assertEquals( 1, soqlCalls, 'query with a minimum date on session cache, when called twice within the required age, will only issue one SOQL statement' );
600
+
System.assertEquals( originalResults, secondResults, 'query with a minimum date on session cache, when called twice within the required age, returns the same results in both calls' );
601
+
602
+
logger.assertNumberOfLogCalls( 0, 'query with a minimum date on session cache,when called twice within the required age, does not generate a log entry' );
603
+
}
604
+
605
+
@isTest
606
+
privatestaticvoidquery_minDate_session_whenCalledTwiceOutsideDate_issuesTwoSoql() // NOPMD: Test method name format
List<Sobject> secondResults=executor.query( soqlStatement, middleDate ); // this date is later than the first query ran, so the cache should not be used
627
+
IntegersoqlCalls=Limits.getQueries();
628
+
Test.stopTest();
629
+
630
+
System.assertEquals( 2, soqlCalls, 'query with a maximum age on session cache, when called twice with the second outside the required age, will issue two SOQL statements' );
631
+
}
632
+
633
+
@isTest
634
+
privatestaticvoidquery_minDate_whenPassedANullMinDate_throwsAnException() // NOPMD: Test method name format
ortoo_Asserts.assertContains( 'query called with a null minimumDateTimeAdded', exceptionMessage, 'query, when passed a null minimumDateTimeAdded, will throw an exception' );
654
+
}
655
+
500
656
@isTest
501
657
privatestaticvoidquery_none_whenRanFor100Queries_willNotThrow() // NOPMD: Test method name format
0 commit comments