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.
Moved the FakeLogger out to TestLoggerService so other classes can us…
…e it
- Loading branch information
1 parent
ab5112f
commit 276ee44
Showing
3 changed files
with
97 additions
and
88 deletions.
There are no files selected for viewing
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
66 changes: 66 additions & 0 deletions
66
framework/default/modules/logger/services/logger/classes/tests/TestLoggerService.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,66 @@ | ||
@isTest | ||
// This exists because StubProvider has difficulty creating a stub for ILoggerService | ||
// Potentially it's a problem with overloaded methods defined in an interface. | ||
public class TestLoggerService implements ILoggerService | ||
{ | ||
class LoggerException extends Exception {} | ||
|
||
public List<String> methods = new List<String>(); | ||
public List<List<Object>> parameters = new List<List<Object>>(); | ||
Boolean defaultLoggingEnabledReturns = false; | ||
Boolean loggingThrowsException = false; | ||
|
||
public TestLoggerService loggingThrowsException() | ||
{ | ||
loggingThrowsException = true; | ||
return this; | ||
} | ||
public TestLoggerService setDefaultLoggingEnabledReturns( Boolean returns ) | ||
{ | ||
defaultLoggingEnabledReturns = returns; | ||
return this; | ||
} | ||
public Boolean getDefaultLoggingEnabled( LoggerService.Level logLevel ) | ||
{ | ||
methods.add( 'getDefaultLoggingEnabled' ); | ||
parameters.add( new List<Object>{ logLevel } ); | ||
return defaultLoggingEnabledReturns; | ||
} | ||
public void log( LoggerService.Level logLevel, String message ) | ||
{ | ||
methods.add( 'log' ); | ||
parameters.add( new List<Object>{ logLevel, message } ); | ||
if ( loggingThrowsException ) | ||
{ | ||
throw new LoggerException( 'a message' ); | ||
} | ||
} | ||
public void log( LoggerService.Level logLevel, String message, Id relatedSobjectId ) | ||
{ | ||
methods.add( 'log' ); | ||
parameters.add( new List<Object>{ logLevel, message, relatedSobjectId } ); | ||
if ( loggingThrowsException ) | ||
{ | ||
throw new LoggerException( 'a message' ); | ||
} | ||
} | ||
public void log( Exception exceptionToLog ) | ||
{ | ||
methods.add( 'log' ); | ||
parameters.add( new List<Object>{ exceptionToLog } ); | ||
if ( loggingThrowsException ) | ||
{ | ||
throw new LoggerException( 'a message' ); | ||
} | ||
} | ||
public void log( Exception exceptionToLog, Id relatedSobject ) | ||
{ | ||
methods.add( 'log' ); | ||
parameters.add( new List<Object>{ exceptionToLog, relatedSobject }); | ||
if ( loggingThrowsException ) | ||
{ | ||
throw new LoggerException( 'a message' ); | ||
} | ||
} | ||
} | ||
|
5 changes: 5 additions & 0 deletions
5
...ework/default/modules/logger/services/logger/classes/tests/TestLoggerService.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>54.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |