Skip to content

Commit

Permalink
Reformatted tests to ensure Clayton picks up testing of the methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-baillie-ortoo committed Mar 10, 2022
1 parent 3b80f95 commit e456765
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}

Expand All @@ -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' );
}

Expand All @@ -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' );
}

Expand All @@ -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' );
}

Expand All @@ -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' );
}

Expand All @@ -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' );
}

Expand All @@ -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' );
Expand All @@ -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' );
Expand Down

0 comments on commit e456765

Please sign in to comment.