diff --git a/framework/default/ortoo-core/default/classes/fflib-extension/caching/tests/NullCacheTest.cls b/framework/default/ortoo-core/default/classes/fflib-extension/caching/tests/NullCacheTest.cls index f0a225f20a3..e1edc93de90 100644 --- a/framework/default/ortoo-core/default/classes/fflib-extension/caching/tests/NullCacheTest.cls +++ b/framework/default/ortoo-core/default/classes/fflib-extension/caching/tests/NullCacheTest.cls @@ -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 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 { diff --git a/framework/default/ortoo-core/default/classes/fflib-extension/caching/tests/OrgCacheTest.cls b/framework/default/ortoo-core/default/classes/fflib-extension/caching/tests/OrgCacheTest.cls index 18a920595b3..9c2559f7f3a 100644 --- a/framework/default/ortoo-core/default/classes/fflib-extension/caching/tests/OrgCacheTest.cls +++ b/framework/default/ortoo-core/default/classes/fflib-extension/caching/tests/OrgCacheTest.cls @@ -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{ '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 diff --git a/framework/default/ortoo-core/default/classes/fflib-extension/caching/tests/SessionCacheTest.cls b/framework/default/ortoo-core/default/classes/fflib-extension/caching/tests/SessionCacheTest.cls index fb1b1c56b9c..8b89febd68e 100644 --- a/framework/default/ortoo-core/default/classes/fflib-extension/caching/tests/SessionCacheTest.cls +++ b/framework/default/ortoo-core/default/classes/fflib-extension/caching/tests/SessionCacheTest.cls @@ -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{ 'key1', 'key2', 'key3', 'key4' }, got, 'getKeys, returns the keys in the cache' ); + } + @isTest private static void contains_whenCalledForAKeyThatWasPut_returnsTrue() // NOPMD: Test method name format {