Skip to content

Commit

Permalink
Added tests for getKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-baillie-ortoo committed Mar 14, 2022
1 parent 72e1eb9 commit 6d1013e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ private without sharing class NullCacheTest
System.assert( true, 'put, when called, will do nothing and not throw an exception' );
}

@isTest
private static void getKeys_whenCalled_returnsAnEmptySet() // NOPMD: Test method name format
{
NullCache cache = new NullCache();
Set<String> got = cache.getKeys();
System.assertEquals( 0, got.size(), 'getKeys, when called, will return an empty set' );
}

@isTest
private static void contains_whenCalled_returnsFalse() // NOPMD: Test method name format
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,43 @@ private without sharing class OrgCacheTest
System.assertEquals( '2', got, 'put, when called multiple times with different keys, stores them' );
}

@isTest
private static void getKeyss_whenTheUserDoesNotHaveAccessToTheCache_throwsAnException() // NOPMD: Test method name format
{
setupAccessToSoqlCache( false );

OrgCache cache = new OrgCache();

Test.startTest();
Exception exceptionThrown;
try
{
cache.getKeys();
}
catch ( OrgCache.AccessViolationException e )
{
exceptionThrown = e;
}
Test.stopTest();

ortoo_Asserts.assertContains( Label.ortoo_core_org_cache_access_violation, exceptionThrown?.getMessage(), 'getKeys, when the user does not have access to the cache, will throw an exception' );
}

@isTest
private static void getKeys_whenCalledByUserWithCacheAccess_returnsTheKeysInTheCache() // NOPMD: Test method name format
{
setupAccessToSoqlCache( true );

new OrgCache().put( 'key1', '1', DEFAULT_LIFESPAN );
new OrgCache().put( 'key2', '2', DEFAULT_LIFESPAN );
new OrgCache().put( 'key3', '3', DEFAULT_LIFESPAN );
new OrgCache().put( 'key4', '4', DEFAULT_LIFESPAN );

OrgCache cache = new OrgCache();
Object got = cache.getKeys();

System.assertEquals( new Set<String>{ 'key1', 'key2', 'key3', 'key4' }, got, 'getKeys, when called by user with cache access, returns the keys in the cache' );
}

@isTest
private static void contains_whenTheUserDoesNotHaveAccessToTheCache_throwsAnException() // NOPMD: Test method name format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ private without sharing class SessionCacheTest
System.assertEquals( '2', got, 'put, when called multiple times with different keys, stores them' );
}


@isTest
private static void getKeys_returnsTheKeysInTheCache() // 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 );

SessionCache cache = new SessionCache();
Object got = cache.getKeys();

System.assertEquals( new Set<String>{ 'key1', 'key2', 'key3', 'key4' }, got, 'getKeys, returns the keys in the cache' );
}

@isTest
private static void contains_whenCalledForAKeyThatWasPut_returnsTrue() // NOPMD: Test method name format
{
Expand Down

0 comments on commit 6d1013e

Please sign in to comment.