Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
Revert "WIP: Code cleanup before next release (#46)" (#47)
Browse files Browse the repository at this point in the history
This reverts commit c2386e7.
  • Loading branch information
jongpie authored Jun 2, 2017
1 parent c2386e7 commit 92d73f5
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 57 deletions.
10 changes: 10 additions & 0 deletions src/classes/CollectionUtils.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*************************************************************************************************
* This file is part of the Nebula Framework project, released under the MIT License. *
* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
*************************************************************************************************/
public class CollectionUtils {

public static Boolean isNullOrEmpty(List<Object> listOfThings) {
return listOfThings == null || listOfThings.isEmpty();
}
}
5 changes: 5 additions & 0 deletions src/classes/CollectionUtils.cls-meta.xml
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>38.0</apiVersion>
<status>Active</status>
</ApexClass>
6 changes: 3 additions & 3 deletions src/classes/DML.cls
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public virtual class DML implements IDML {
}

public virtual SObject doUpsert(SObject record) {
// Salesforce will only allow upsert calls for SObjects if a declared-type list is passed in.
// This is fine for the bulk method, where we can assume the caller is passing in an explicit list, but for a single record,
// the only way to successfully perform the upsert is to dynamically spin up a list of the SObject's type
//Salesforce will only allow upsert calls for SObjects if a declared-type list is passed in.
//This is fine for the bulk method, where we can assume the caller is passing in an explicit list, but for a single record,
//the only way to successfully perform the upsert is to dynamically spin up a list of the SObject's type
String listType = 'List<' + record.getSObjectType() + '>';
List<SObject> castRecords = (List<SObject>)Type.forName(listType).newInstance();
castRecords.add(record);
Expand Down
7 changes: 4 additions & 3 deletions src/classes/DMLMock.cls
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
*************************************************************************************************/
public virtual class DMLMock implements IDML {

// DML
public SObject doInsert(SObject record) { return this.doInsert(new List<SObject>{record})[0]; }
public List<SObject> doInsert(List<SObject> recordList) {
TestingUtils.generateIds(recordList);
Expand Down Expand Up @@ -32,10 +32,11 @@ public virtual class DMLMock implements IDML {

public void doDelete(SObject record) { this.doDelete(new List<SObject>{record}); }
public void doDelete(List<SObject> recordList) {
if(recordList != null) TestingUtils.deletedRecords.addAll(recordList);
if(!CollectionUtils.IsNullOrEmpty(recordList)) {
TestingUtils.deletedRecords.addAll(recordList);
}
}

public void doHardDelete(SObject record) { this.doHardDelete(new List<SObject>{record}); }
public void doHardDelete(List<SObject> recordList) { this.doDelete(recordList); }

}
6 changes: 0 additions & 6 deletions src/classes/DMLMock_Tests.cls
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/*************************************************************************************************
* This file is part of the Nebula Framework project, released under the MIT License. *
* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
*************************************************************************************************/
@isTest
private class DMLMock_Tests {

static IDML dmlRepo = new DMLMock();
static Schema.Contact con = createContact();

Expand Down Expand Up @@ -85,5 +80,4 @@ private class DMLMock_Tests {

return con;
}

}
6 changes: 0 additions & 6 deletions src/classes/DML_Tests.cls
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/*************************************************************************************************
* This file is part of the Nebula Framework project, released under the MIT License. *
* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
*************************************************************************************************/
@isTest
private class DML_Tests {

static IDML dml = new DML();
static Contact contact = createContact();

Expand Down Expand Up @@ -90,5 +85,4 @@ private class DML_Tests {

return contact;
}

}
1 change: 1 addition & 0 deletions src/classes/Exceptions.cls
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*************************************************************************************************/
public without sharing class Exceptions {

public class DescribeException extends Exception {}
public class InvalidOperationException extends Exception {}
public class RecordTypeException extends Exception {}
public class SObjectTriggerHandlerException extends Exception {}
Expand Down
4 changes: 0 additions & 4 deletions src/classes/IQueryFilter.cls
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/*************************************************************************************************
* This file is part of the Nebula Framework project, released under the MIT License. *
* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
*************************************************************************************************/
public interface IQueryFilter {

String getValue();
Expand Down
14 changes: 7 additions & 7 deletions src/classes/QueryBuilder.cls
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ public without sharing class QueryBuilder extends NebulaCore implements IQueryBu
private final Map<String, Schema.SObjectField> sobjectTypeFieldMap;

public QueryBuilder(Schema.SObjectType sobjectType, Schema.FieldSet fieldSet, List<Schema.SObjectField> sobjectFieldList) {
this.sobjectType = sobjectType;
this.sobjectFieldList = sobjectFieldList;
this.fieldSet = fieldSet;
this.sobjectTypeFieldMap = this.sobjectType.getDescribe().fields.getMap();
this.sobjectType = sobjectType;
this.sobjectFieldList = sobjectFieldList;
this.fieldSet = fieldSet;

this.forUpdate = false;
this.queryFields = new Set<String>();
this.childRelationshipQueries = new List<String>();
this.whereClauseList = new List<String>();
this.orderByList = new List<String>();
this.forUpdate = false;
this.sobjectTypeFieldMap = this.sobjectType.getDescribe().fields.getMap();
this.whereClauseList = new List<String>();
this.childRelationshipQueries = new List<String>();

this.addCommonQueryFields();
this.addFieldSetMembers();
Expand Down
2 changes: 1 addition & 1 deletion src/classes/QueryDateLiteral_Tests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@isTest
public class QueryDateLiteral_Tests {

private static Integer n_number = 5;
private static integer n_number = 5;

@isTest
static void it_should_return_yesterday_string() {
Expand Down
1 change: 1 addition & 0 deletions src/classes/SObjectFieldDescriber_Tests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* This file is part of the Nebula Framework project, released under the MIT License. *
* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
*************************************************************************************************/

@isTest
private class SObjectFieldDescriber_Tests {

Expand Down
30 changes: 24 additions & 6 deletions src/classes/SObjectRepositoryMocks.cls
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,41 @@ public class SObjectRepositoryMocks {
}

private void createMockObjects() {
// We would expect that for the Ids passed in, there will be a corresponding number of records returned of the exact same
// SObjectType as their Ids.
//We would expect that for the Ids passed in, there will be a corresponding number of records returned of the exact same
//SObjectType as their Ids.
this.records = new List<SObject>();
for(Id recordId : this.recordIdList) {
SObjectType objType = recordId.getSObjectType();
for(Id thing : this.recordIdList) {
SObjectType objType = thing.getSObjectType();
SObject record = (SObject)Type.forName(String.valueOf(objType)).newInstance();
record.put('Id', recordId);
record.put('Id', thing);

this.records.add(record);
}
}

private List<SObject> returnListOfSObjects() {
if(this.records == null) return new List<SObject>();
if(CollectionUtils.isNullOrEmpty(this.records)) return new List<SObject>();

return this.records;
}

private SObjectType getSObjectType(Schema.SObjectField field) {
//There is supposed to be a built in Salesforce getDescribe() result for Schema.SObjectField, getReferenceTo()
//that should return a list of objects that field is associated with, but it has been broken for several years.
//This is a solution that was proposed on the Salesforce stack exchange and is the only work-around to a native lookup
//that I have been able to find.
Integer fieldHash = ((Object)field).hashCode();

// Build a map of hashcodes for each fieldDescribe taken from Schema Global Describe
Map<String, Schema.SObjectType> globalDescribe = Schema.getGlobalDescribe();
Map<Integer,Schema.SObjectType> fieldHashCodeToSObjectTypeMap = new Map<Integer,Schema.SObjectType>();
for (String sobjname: globalDescribe.keySet()) {
for (Schema.SObjectField sobjField : globalDescribe.get(sObjName).getDescribe().fields.getMap().values())
fieldHashCodeToSObjectTypeMap.put(((Object) sObjField).hashCode(), globalDescribe.get(sobjName));
}

return fieldHashCodeToSObjectTypeMap.get(fieldHash);
}
}

}
12 changes: 8 additions & 4 deletions src/classes/SObjectTriggerHandler.cls
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ public abstract class SObjectTriggerHandler extends NebulaCore implements ISObje

private static Map<Integer, Set<TriggerContext>> hashCodesForProcessedRecords = new Map<Integer, Set<TriggerContext>>();

@testVisible private enum TriggerContext {
@testVisible
private enum TriggerContext {
BEFORE_INSERT, BEFORE_UPDATE, BEFORE_DELETE,
AFTER_INSERT, AFTER_UPDATE, AFTER_DELETE, AFTER_UNDELETE
}
@testVisible private TriggerContext context; // The current context of the trigger
@testVisible
private TriggerContext context; // The current context of the trigger

private Integer hashCode; // The hash code for the current records
private Boolean isTestMode;
private Boolean isTriggerExecuting; // Checks if the code was called by a trigger

@testVisible private List<SObject> recordList, oldRecordList;
@testVisible private Map<Id, SObject> recordMap, oldRecordMap;
@testVisible
private List<SObject> recordList, oldRecordList;
@testVisible
private Map<Id, SObject> recordMap, oldRecordMap;

public SObjectTriggerHandler() {
this(false);
Expand Down
7 changes: 0 additions & 7 deletions src/classes/SObjectTriggerHandler_Tests.cls
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/*************************************************************************************************
* This file is part of the Nebula Framework project, released under the MIT License. *
* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
*************************************************************************************************/
@isTest
private class SObjectTriggerHandler_Tests {

private class LeadTriggerHandlerTest extends SObjectTriggerHandler {
public LeadTriggerHandlerTest() {
super(true);
Expand All @@ -24,7 +19,6 @@ private class SObjectTriggerHandler_Tests {
}

static List<Lead> leadList = new List<Lead>();

static void setupData() {
for(Integer i = 0; i < 5; i++) {
Lead lead = new Lead(
Expand Down Expand Up @@ -98,5 +92,4 @@ private class SObjectTriggerHandler_Tests {

// Test.stopTest();
// }

}
4 changes: 0 additions & 4 deletions src/classes/SObjectTypeDescriber.cls
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/*************************************************************************************************
* This file is part of the Nebula Framework project, released under the MIT License. *
* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
*************************************************************************************************/
public without sharing class SObjectTypeDescriber {

public Schema.SObjectType SObjectType {get; private set;}
Expand Down
10 changes: 6 additions & 4 deletions src/classes/SObjectTypeDescriber_Tests.cls
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/*************************************************************************************************
* This file is part of the Nebula Framework project, released under the MIT License. *
* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
*************************************************************************************************/
@isTest
private class SObjectTypeDescriber_Tests {

Expand Down Expand Up @@ -46,8 +42,10 @@ private class SObjectTypeDescriber_Tests {
Schema.SObjectType expectedSObjectType = Schema.Lead.SObjectType;

Test.startTest();

SObjectTypeDescriber sobjectTypeDescriber = new SObjectTypeDescriber(expectedSObjectType);
System.assertEquals(expectedSObjectType, sobjectTypeDescriber.SObjectType);

Test.stopTest();
}

Expand All @@ -56,7 +54,9 @@ private class SObjectTypeDescriber_Tests {
SObjectTypeDescriber sobjectTypeDescriber = new SObjectTypeDescriber(Schema.Lead.SObjectType);

Test.startTest();

System.assertEquals(true, sobjectTypeDescriber.validateSObjectFieldExists(Schema.Lead.Id));

Test.stopTest();
}

Expand All @@ -65,7 +65,9 @@ private class SObjectTypeDescriber_Tests {
SObjectTypeDescriber sobjectTypeDescriber = new SObjectTypeDescriber(Schema.Lead.SObjectType);

Test.startTest();

System.assertEquals(false, sobjectTypeDescriber.validateSObjectFieldExists(Schema.Task.Id));

Test.stopTest();
}

Expand Down
3 changes: 1 addition & 2 deletions src/classes/TestingUtils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class TestingUtils {
}

public static SObject setReadOnlyField(SObject sobj, SObjectField fieldName, String value) {
return setReadOnlyField(sobj, new Map<SObjectField,String>{fieldName => value});
return setReadOnlyField(sobj,new Map<SObjectField,String>{fieldName => value});
}

public static SObject setReadOnlyField(SObject sobj, Map<SObjectField,String> changesToFields) {
Expand All @@ -44,5 +44,4 @@ public class TestingUtils {

return (SObject)JSON.deserialize(serializedRecord, SObject.class);
}

}

0 comments on commit 92d73f5

Please sign in to comment.