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.
Added test and documentation for the cache entry
Added categories to the docs for the caching classes
- Loading branch information
1 parent
08124af
commit 807239c
Showing
9 changed files
with
116 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
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
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
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
78 changes: 78 additions & 0 deletions
78
...ework/default/ortoo-core/default/classes/fflib-extension/caching/tests/CacheEntryTest.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,78 @@ | ||
@isTest | ||
private without sharing class CacheEntryTest | ||
{ | ||
@isTest | ||
private static void getValue_whenCalled_returnsTheValue() // NOPMD: Test method name format | ||
{ | ||
Object expected = 'thevalue'; | ||
CacheEntry entry = new CacheEntry( expected ); | ||
|
||
Test.startTest(); | ||
Object got = entry.getValue(); | ||
Test.stopTest(); | ||
|
||
System.assertEquals( expected, got, 'getValue, when called, will return the value' ); | ||
} | ||
|
||
@isTest | ||
private static void isYoungerThanOrEqualTo_whenTheCacheIsYounger_returnsTrue() // NOPMD: Test method name format | ||
{ | ||
TestDateTimeUtils.setCurrentDateTime( 0 ); | ||
CacheEntry entry = new CacheEntry( 'TheCachedEntry' ); | ||
|
||
Test.startTest(); | ||
TestDateTimeUtils.addToCurrentTime( 100 ); // this means the cache entry is 100 seconds old | ||
Boolean got = entry.isYoungerThanOrEqualTo( 150 ); | ||
Test.stopTest(); | ||
|
||
System.assert( got, 'isYoungerThanOrEqualTo, when the cache entry is younger, will return true' ); | ||
} | ||
|
||
@isTest | ||
private static void isYoungerThanOrEqualTo_whenTheCacheIsExactlyTheGivenAge_returnsTrue() // NOPMD: Test method name format | ||
{ | ||
TestDateTimeUtils.setCurrentDateTime( 0 ); | ||
CacheEntry entry = new CacheEntry( 'TheCachedEntry' ); | ||
|
||
Test.startTest(); | ||
TestDateTimeUtils.addToCurrentTime( 100 ); // this means the cache entry is 100 seconds old | ||
Boolean got = entry.isYoungerThanOrEqualTo( 100 ); | ||
Test.stopTest(); | ||
|
||
System.assert( got, 'isYoungerThanOrEqualTo, when the cache entry is exactly the stated age, will return true' ); | ||
} | ||
|
||
@isTest | ||
private static void isYoungerThanOrEqualTo_whenTheCacheIsOlder_returnsFalse() // NOPMD: Test method name format | ||
{ | ||
TestDateTimeUtils.setCurrentDateTime( 0 ); | ||
CacheEntry entry = new CacheEntry( 'TheCachedEntry' ); | ||
|
||
Test.startTest(); | ||
TestDateTimeUtils.addToCurrentTime( 100 ); // this means the cache entry is 100 seconds old | ||
Boolean got = entry.isYoungerThanOrEqualTo( 50 ); | ||
Test.stopTest(); | ||
|
||
System.assert( ! got, 'isYoungerThanOrEqualTo, when the cache entry is older, will return false' ); | ||
} | ||
|
||
@isTest | ||
private static void isYoungerThanOrEqualTo_whenPassedANullAge_throwsAnException() // NOPMD: Test method name format | ||
{ | ||
CacheEntry entry = new CacheEntry( 'TheCachedEntry' ); | ||
|
||
Test.startTest(); | ||
String exceptionMessage; | ||
try | ||
{ | ||
entry.isYoungerThanOrEqualTo( null ); | ||
} | ||
catch ( Contract.RequiresException e ) | ||
{ | ||
exceptionMessage = e.getMessage(); | ||
} | ||
Test.stopTest(); | ||
|
||
ortoo_Asserts.assertContains( 'isYoungerThanOrEqualTo called with a null compareAgeInSeconds', exceptionMessage, 'isYoungerThanOrEqualTo, when passed a null age, will throw an exception' ); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...ault/ortoo-core/default/classes/fflib-extension/caching/tests/CacheEntryTest.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> |