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 robustness to SessionCache
Fixed missing assertion text from NullDomainTest
- Loading branch information
1 parent
3906e1a
commit 525aa2c
Showing
5 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
framework/default/ortoo-core/default/classes/fflib-extension/caching/NullCache.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
98 changes: 98 additions & 0 deletions
98
...ork/default/ortoo-core/default/classes/fflib-extension/caching/tests/SessionCacheTest.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,98 @@ | ||
@isTest | ||
private without sharing class SessionCacheTest | ||
{ | ||
private final static Integer DEFAULT_LIFESPAN = 1000; | ||
|
||
@isTest | ||
private static void hasAccessToCache_whenCalled_returnsTrue() // NOPMD: Test method name format | ||
{ | ||
Boolean got = new SessionCache().hasAccessToCache(); | ||
System.assertEquals( true, got, 'hasAccessToCache, when called, will return true' ); | ||
} | ||
|
||
@isTest | ||
private static void isACache_whenCalled_returnsTrue() // NOPMD: Test method name format | ||
{ | ||
Boolean got = new SessionCache().isACache(); | ||
System.assertEquals( true, got, 'hasAccessToCache, when called, will return true' ); | ||
} | ||
|
||
@isTest | ||
private static void get_whenCalledWithAKeyNotInTheCache_returnsNull() // NOPMD: Test method name format | ||
{ | ||
Object got = new SessionCache().get( 'doesnotexist' ); | ||
System.assertEquals( null, got, 'get, when called with a key that is not in the cache, will return null' ); | ||
} | ||
|
||
@isTest | ||
private static void get_whenCalledWithAKeyThatWasPut_returnsIt() // NOPMD: Test method name format | ||
{ | ||
String expected = 'thecachedthing'; | ||
new SessionCache().put( 'key', expected, DEFAULT_LIFESPAN ); | ||
|
||
Object got = new SessionCache().get( 'key' ); | ||
System.assertEquals( expected, got, 'get, when called with a key that is in the cache, will return it' ); | ||
} | ||
|
||
@isTest | ||
private static void put_whenCalledMultipleTimesWithTheSameKey_overwritesIt() // NOPMD: Test method name format | ||
{ | ||
new SessionCache().put( 'key', '1', DEFAULT_LIFESPAN ); | ||
new SessionCache().put( 'key', '2', DEFAULT_LIFESPAN ); | ||
new SessionCache().put( 'key', '3', DEFAULT_LIFESPAN ); | ||
new SessionCache().put( 'key', '4', DEFAULT_LIFESPAN ); | ||
|
||
Object got = new SessionCache().get( 'key' ); | ||
System.assertEquals( '4', got, 'put, when called multiple times with the same key, overwrites it' ); | ||
} | ||
|
||
@isTest | ||
private static void put_whenCalledMultipleTimesWithDifferentKeys_storesThem() // NOPMD: Test method name format | ||
{ | ||
new SessionCache().put( 'key1', '1', DEFAULT_LIFESPAN ); | ||
new SessionCache().put( 'key2', '2', DEFAULT_LIFESPAN ); | ||
new SessionCache().put( 'key3', '3', DEFAULT_LIFESPAN ); | ||
new SessionCache().put( 'key4', '4', DEFAULT_LIFESPAN ); | ||
|
||
Object got = new SessionCache().get( 'key2' ); | ||
System.assertEquals( '2', got, 'put, when called multiple times with different keys, stores them' ); | ||
} | ||
|
||
@isTest | ||
private static void contains_whenCalledForAKeyThatWasPut_returnsTrue() // NOPMD: Test method name format | ||
{ | ||
new SessionCache().put( 'keythatexists', '1', DEFAULT_LIFESPAN ); | ||
|
||
Boolean got = new SessionCache().contains( 'keythatexists' ); | ||
System.assertEquals( true, got, 'contains, when called for a key that was put, returns true' ); | ||
} | ||
|
||
@isTest | ||
private static void contains_whenCalledForAKeyThatWasNotPut_returnsFalse() // NOPMD: Test method name format | ||
{ | ||
new SessionCache().put( 'keythatexists', '1', DEFAULT_LIFESPAN ); | ||
|
||
Boolean got = new SessionCache().contains( 'keythatdoesnotexist' ); | ||
System.assertEquals( false, got, 'contains, when called for a key that was not put, returns false' ); | ||
} | ||
|
||
@isTest | ||
private static void remove_whenCalledForAKeyThatWasPut_removesIt() // NOPMD: Test method name format | ||
{ | ||
new SessionCache().put( 'originalkey', '1', DEFAULT_LIFESPAN ); | ||
|
||
new SessionCache().remove( 'originalkey' ); | ||
|
||
System.assertEquals( false, new SessionCache().contains( 'originalkey' ), 'remove, when called for a key that was put, will remove it - checking contains' ); | ||
System.assertEquals( null, new SessionCache().get( 'originalkey' ), 'remove, when called for a key that was put, will remove it - checking get' ); | ||
} | ||
|
||
@isTest | ||
private static void remove_whenCalledForAKeyThatWasNotPut_doesNotError() // NOPMD: Test method name format | ||
{ | ||
new SessionCache().remove( 'keythatneverexisted' ); | ||
|
||
System.assertEquals( false, new SessionCache().contains( 'keythatneverexisted' ), 'remove, when called for a key that was put, will remove it - checking contains' ); | ||
System.assertEquals( null, new SessionCache().get( 'keythatneverexisted' ), 'remove, when called for a key that was put, will remove it - checking get' ); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...lt/ortoo-core/default/classes/fflib-extension/caching/tests/SessionCacheTest.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> |
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