From e456765293a48c1353db5297a94ff8096cd82bc8 Mon Sep 17 00:00:00 2001 From: Robert Baillie Date: Thu, 10 Mar 2022 15:47:17 +0000 Subject: [PATCH] Reformatted tests to ensure Clayton picks up testing of the methods --- .../caching/tests/NullCacheTest.cls | 18 ++++++++---- .../caching/tests/SessionCacheTest.cls | 29 ++++++++++++------- 2 files changed, 31 insertions(+), 16 deletions(-) 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 a4c62694f59..f0a225f20a3 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 @@ -4,42 +4,48 @@ private without sharing class NullCacheTest @isTest private static void hasAccessToCache_whenCalled_returnsTrue() // NOPMD: Test method name format { - Boolean got = new NullCache().hasAccessToCache(); + NullCache cache = new NullCache(); + Boolean got = cache.hasAccessToCache(); System.assertEquals( true, got, 'hasAccessToCache, when called, will return true' ); } @isTest private static void isACache_whenCalled_returnsFalse() // NOPMD: Test method name format { - Boolean got = new NullCache().isACache(); + NullCache cache = new NullCache(); + Boolean got = cache.isACache(); System.assertEquals( false, got, 'hasAccessToCache, when called, will return false' ); } @isTest private static void get_whenCalled_returnsNull() // NOPMD: Test method name format { - Object got = new NullCache().get( null ); + NullCache cache = new NullCache(); + Object got = cache.get( null ); System.assertEquals( null, got, 'get, when called, will return null' ); } @isTest private static void put_whenCalled_doesNothing() // NOPMD: Test method name format { - new NullCache().put( null, null, null ); + NullCache cache = new NullCache(); + cache.put( null, null, null ); System.assert( true, 'put, when called, will do nothing and not throw an exception' ); } @isTest private static void contains_whenCalled_returnsFalse() // NOPMD: Test method name format { - Boolean got = new NullCache().contains( null ); + NullCache cache = new NullCache(); + Boolean got = cache.contains( null ); System.assertEquals( false, got, 'contains, when called, will return false' ); } @isTest private static void remove_whenCalled_doesNothing() // NOPMD: Test method name format { - new NullCache().remove( null ); + NullCache cache = new NullCache(); + cache.remove( null ); System.assert( true, 'remove, when called, will do nothing and not throw an exception' ); } } \ No newline at end of file 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 5bcdfb4067e..92d2f517f15 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 @@ -6,21 +6,24 @@ private without sharing class SessionCacheTest @isTest private static void hasAccessToCache_whenCalled_returnsTrue() // NOPMD: Test method name format { - Boolean got = new SessionCache().hasAccessToCache(); + SessionCache cache = new SessionCache(); + Boolean got = cache.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(); + SessionCache cache = new SessionCache(); + Boolean got = cache.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' ); + SessionCache cache = new SessionCache(); + Object got = cache.get( 'doesnotexist' ); System.assertEquals( null, got, 'get, when called with a key that is not in the cache, will return null' ); } @@ -30,7 +33,8 @@ private without sharing class SessionCacheTest String expected = 'thecachedthing'; new SessionCache().put( 'key', expected, DEFAULT_LIFESPAN ); - Object got = new SessionCache().get( 'key' ); + SessionCache cache = new SessionCache(); + Object got = cache.get( 'key' ); System.assertEquals( expected, got, 'get, when called with a key that is in the cache, will return it' ); } @@ -42,7 +46,8 @@ private without sharing class SessionCacheTest new SessionCache().put( 'key', '3', DEFAULT_LIFESPAN ); new SessionCache().put( 'key', '4', DEFAULT_LIFESPAN ); - Object got = new SessionCache().get( 'key' ); + SessionCache cache = new SessionCache(); + Object got = cache.get( 'key' ); System.assertEquals( '4', got, 'put, when called multiple times with the same key, overwrites it' ); } @@ -54,7 +59,8 @@ private without sharing class SessionCacheTest new SessionCache().put( 'key3', '3', DEFAULT_LIFESPAN ); new SessionCache().put( 'key4', '4', DEFAULT_LIFESPAN ); - Object got = new SessionCache().get( 'key2' ); + SessionCache cache = new SessionCache(); + Object got = cache.get( 'key2' ); System.assertEquals( '2', got, 'put, when called multiple times with different keys, stores them' ); } @@ -63,7 +69,8 @@ private without sharing class SessionCacheTest { new SessionCache().put( 'keythatexists', '1', DEFAULT_LIFESPAN ); - Boolean got = new SessionCache().contains( 'keythatexists' ); + SessionCache cache = new SessionCache(); + Boolean got = cache.contains( 'keythatexists' ); System.assertEquals( true, got, 'contains, when called for a key that was put, returns true' ); } @@ -72,7 +79,8 @@ private without sharing class SessionCacheTest { new SessionCache().put( 'keythatexists', '1', DEFAULT_LIFESPAN ); - Boolean got = new SessionCache().contains( 'keythatdoesnotexist' ); + SessionCache cache = new SessionCache(); + Boolean got = cache.contains( 'keythatdoesnotexist' ); System.assertEquals( false, got, 'contains, when called for a key that was not put, returns false' ); } @@ -81,7 +89,8 @@ private without sharing class SessionCacheTest { new SessionCache().put( 'originalkey', '1', DEFAULT_LIFESPAN ); - new SessionCache().remove( 'originalkey' ); + SessionCache cache = new SessionCache(); + cache.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' ); @@ -90,7 +99,7 @@ private without sharing class SessionCacheTest @isTest private static void remove_whenCalledForAKeyThatWasNotPut_doesNotError() // NOPMD: Test method name format { - new SessionCache().remove( 'keythatneverexisted' ); + cache.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' );