Skip to content

Commit

Permalink
[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
jongpie committed Sep 10, 2024
1 parent 7ec938c commit 890f2f9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ global without sharing class CallableLogger implements System.Callable {
}

private LogEntryEventBuilder newEntry(Map<String, Object> arguments) {
System.LoggingLevel loggingLevel = (System.LoggingLevel) arguments.get(ARGUMENT_LOGGING_LEVEL);
// The value of loggingLevel could be either a string name or enum value,
// so coerce it to a string for consistency
String loggingLevelName = '' + arguments.get(ARGUMENT_LOGGING_LEVEL);
System.LoggingLevel loggingLevel = Logger.getLoggingLevel(loggingLevelName);
String message = (String) arguments.get(ARGUMENT_MESSAGE);

LogEntryEventBuilder logEntryEventBuilder = Logger.newEntry(loggingLevel, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private class CallableLogger_Tests {
}

@IsTest
static void it_adds_new_entry() {
static void it_adds_new_entry_using_logging_level_enum() {
System.LoggingLevel loggingLevel = System.LoggingLevel.FINE;
String message = 'some log entry message';

Expand All @@ -112,6 +112,21 @@ private class CallableLogger_Tests {
System.Assert.areEqual(message, logEntryEvent.Message__c);
}

@IsTest
static void it_adds_new_entry_using_logging_level_name() {
String loggingLevelName = System.LoggingLevel.FINE.name();
String message = 'some log entry message';

System.Callable callableLoggerInstance = (System.Callable) System.Type.forName('CallableLogger').newInstance();
Object returnedValue = callableLoggerInstance.call('newEntry', new Map<String, Object>{ 'loggingLevel' => loggingLevelName, 'message' => message });

System.Assert.isNotNull(returnedValue);
System.Assert.isInstanceOfType(returnedValue, LogEntryEventBuilder.class);
LogEntryEvent__e logEntryEvent = ((LogEntryEventBuilder) returnedValue).getLogEntryEvent();
System.Assert.areEqual(loggingLevelName, logEntryEvent.LoggingLevel__c);
System.Assert.areEqual(message, logEntryEvent.Message__c);
}

@IsTest
static void it_adds_new_entry_with_exception() {
System.LoggingLevel loggingLevel = System.LoggingLevel.FINE;
Expand Down

0 comments on commit 890f2f9

Please sign in to comment.