Skip to content

Commit

Permalink
Updated several config classes to consistently have test-visible priv…
Browse files Browse the repository at this point in the history
…ate methods before non-test-visible private methods
  • Loading branch information
jongpie committed Jul 7, 2024
1 parent 0732310 commit e8eb17e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,15 @@ public class LoggerParameter {
return matchingParameters;
}

@TestVisible
private static void setMock(LoggerParameter__mdt parameter) {
if (String.isBlank(parameter.DeveloperName)) {
throw new System.IllegalArgumentException('DeveloperName is required on `LoggerParameter__mdt: \n' + JSON.serializePretty(parameter));
}

DEVELOPER_NAME_TO_RECORD.put(parameter.DeveloperName, parameter);
}

private static Map<String, LoggerParameter__mdt> loadRecords() {
Map<String, LoggerParameter__mdt> parameters = LoggerParameter__mdt.getAll().clone();
if (System.Test.isRunningTest()) {
Expand All @@ -799,15 +808,6 @@ public class LoggerParameter {
return parameters;
}

@TestVisible
private static void setMock(LoggerParameter__mdt parameter) {
if (String.isBlank(parameter.DeveloperName)) {
throw new System.IllegalArgumentException('DeveloperName is required on `LoggerParameter__mdt: \n' + JSON.serializePretty(parameter));
}

DEVELOPER_NAME_TO_RECORD.put(parameter.DeveloperName, parameter);
}

private static Object castParameterValue(String parameterDeveloperName, System.Type dataType) {
String parameterValue = loadParameterValue(parameterDeveloperName);
if (parameterValue == null) {
Expand Down
20 changes: 10 additions & 10 deletions nebula-logger/core/main/configuration/classes/LoggerPlugin.cls
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ public without sharing class LoggerPlugin {
return (Triggerable) pluginInstance;
}

@TestVisible
private static void setMock(LoggerPlugin__mdt pluginConfiguration) {
if (String.isBlank(pluginConfiguration.DeveloperName)) {
throw new System.IllegalArgumentException('DeveloperName is required on mock LoggerPlugin__mdt: \n' + JSON.serializePretty(pluginConfiguration));
}
if (pluginConfiguration.IsEnabled__c) {
DEVELOPER_NAME_TO_RECORD.put(pluginConfiguration.DeveloperName, pluginConfiguration);
}
}

private static Object newPluginInstance(String apexClassTypeName) {
return System.Type.forName(apexClassTypeName)?.newInstance();
}
Expand All @@ -115,16 +125,6 @@ public without sharing class LoggerPlugin {
return pluginDeveloperNameToConfiguration;
}

@TestVisible
private static void setMock(LoggerPlugin__mdt pluginConfiguration) {
if (String.isBlank(pluginConfiguration.DeveloperName)) {
throw new System.IllegalArgumentException('DeveloperName is required on mock LoggerPlugin__mdt: \n' + JSON.serializePretty(pluginConfiguration));
}
if (pluginConfiguration.IsEnabled__c) {
DEVELOPER_NAME_TO_RECORD.put(pluginConfiguration.DeveloperName, pluginConfiguration);
}
}

@SuppressWarnings('PMD.ApexDoc')
private class PluginConfigurationSorter implements Comparable {
public LoggerPlugin__mdt pluginConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ public without sharing class LoggerFieldMapper {
}
}

@TestVisible
private static void setMock(LoggerFieldMapping__mdt fieldMapping) {
if (String.isBlank(fieldMapping.DeveloperName)) {
throw new System.IllegalArgumentException('DeveloperName is required on `LoggerFieldMapping__mdt: \n' + JSON.serializePretty(fieldMapping));
}

addFieldMapping(fieldMapping, SOURCE_SOBJECT_TYPE_TO_TARGET_FIELD_MAPPINGS);
}

@SuppressWarnings('PMD.ApexCrudViolation')
private static Map<Schema.SObjectType, Map<Schema.SObjectType, List<LoggerFieldMapping__mdt>>> loadRecords() {
// TODO decide if this query should be moved to LogManagementDataSelector
Expand Down Expand Up @@ -133,13 +142,4 @@ public without sharing class LoggerFieldMapper {
private static Schema.SObjectField getSObjectField(Schema.SObjectType sobjectType, String fieldApiName) {
return sobjectType.getDescribe().fields.getMap().get(fieldApiName);
}

@TestVisible
private static void setMock(LoggerFieldMapping__mdt fieldMapping) {
if (String.isBlank(fieldMapping.DeveloperName)) {
throw new System.IllegalArgumentException('DeveloperName is required on `LoggerFieldMapping__mdt: \n' + JSON.serializePretty(fieldMapping));
}

addFieldMapping(fieldMapping, SOURCE_SOBJECT_TYPE_TO_TARGET_FIELD_MAPPINGS);
}
}

0 comments on commit e8eb17e

Please sign in to comment.