Merge pull request #53 from wimvelzeboer/IncreateCodeCoverage
Increase code coverage
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
mkdir ./temp
|
mkdir ./temp || true
|
||||||
cd ./temp
|
cd ./temp
|
||||||
rm -Rf fflib-apex-mocks/
|
rm -Rf fflib-apex-mocks/
|
||||||
rm -Rf fflib-apex-common/
|
rm -Rf fflib-apex-common/
|
||||||
|
|||||||
-5
@@ -32,11 +32,6 @@ public virtual class fflib_ClassicSelectorFactory
|
|||||||
extends fflib_Application.SelectorFactory
|
extends fflib_Application.SelectorFactory
|
||||||
implements fflib_ISelectorFactory
|
implements fflib_ISelectorFactory
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Constructs a simple Selector Factory
|
|
||||||
**/
|
|
||||||
public fflib_ClassicSelectorFactory() {}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a Selector Factory linking SObjectType's with Apex Classes implement the fflib_ISObjectSelector interface
|
* Constructs a Selector Factory linking SObjectType's with Apex Classes implement the fflib_ISObjectSelector interface
|
||||||
* Note that the factory does not check the given Apex Classes implement the interface
|
* Note that the factory does not check the given Apex Classes implement the interface
|
||||||
|
|||||||
+5
-3
@@ -49,6 +49,7 @@ public with sharing class fflib_AppBindingMetaDataModule
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestVisible
|
||||||
private Object getBindingObject(fflib_AppBinding__mdt binding)
|
private Object getBindingObject(fflib_AppBinding__mdt binding)
|
||||||
{
|
{
|
||||||
if (String.isBlank(binding.BindingObject__c) && String.isBlank(binding.BindingObjectAlternate__c)) return null;
|
if (String.isBlank(binding.BindingObject__c) && String.isBlank(binding.BindingObjectAlternate__c)) return null;
|
||||||
@@ -58,12 +59,12 @@ public with sharing class fflib_AppBindingMetaDataModule
|
|||||||
: binding.BindingObjectAlternate__c.toLowerCase().trim();
|
: binding.BindingObjectAlternate__c.toLowerCase().trim();
|
||||||
|
|
||||||
// Assume its an SObjectType
|
// Assume its an SObjectType
|
||||||
List<Schema.DescribeSObjectResult> schemaDescribes = Schema.describeSObjects(new List<String> {bindingObjectApiName});
|
try
|
||||||
if (schemaDescribes.size() == 1)
|
|
||||||
{
|
{
|
||||||
|
List<Schema.DescribeSObjectResult> schemaDescribes = Schema.describeSObjects(new List<String> {bindingObjectApiName});
|
||||||
return schemaDescribes.get(0).getSObjectType();
|
return schemaDescribes.get(0).getSObjectType();
|
||||||
}
|
}
|
||||||
else
|
catch (InvalidParameterValueException e)
|
||||||
{
|
{
|
||||||
// check if its an Object (class)
|
// check if its an Object (class)
|
||||||
Type objectType = System.Type.forName(bindingObjectApiName);
|
Type objectType = System.Type.forName(bindingObjectApiName);
|
||||||
@@ -93,6 +94,7 @@ public with sharing class fflib_AppBindingMetaDataModule
|
|||||||
return bindingTypeByStrings.get(binding.Type__c.toUpperCase());
|
return bindingTypeByStrings.get(binding.Type__c.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestVisible
|
||||||
private Type getSystemType(fflib_AppBinding__mdt binding, Schema.SObjectField sObjectField)
|
private Type getSystemType(fflib_AppBinding__mdt binding, Schema.SObjectField sObjectField)
|
||||||
{
|
{
|
||||||
String systemTypeName = String.valueOf(binding.get(sObjectField));
|
String systemTypeName = String.valueOf(binding.get(sObjectField));
|
||||||
|
|||||||
-36
@@ -96,42 +96,6 @@ public virtual class fflib_AppBindingResolver
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public fflib_IAppBindingResolver byObject(Object bindingObject)
|
|
||||||
{
|
|
||||||
this.bindingToResolve.setBindingObject(bindingObject);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public fflib_IAppBindingResolver bySequence(Integer sequence)
|
|
||||||
{
|
|
||||||
this.bindingToResolve.setSequence(sequence);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public fflib_IAppBindingResolver byType(fflib_AppBindingType bindingType)
|
|
||||||
{
|
|
||||||
this.bindingToResolve.setBindingType(bindingType);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public fflib_IAppBindingResolver byInterfaceType(Type interfaceType)
|
|
||||||
{
|
|
||||||
this.bindingToResolve.setInterfaceType(interfaceType);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public fflib_IAppBindingResolver byNamespacePrefix(String namespacePrefix)
|
|
||||||
{
|
|
||||||
this.bindingToResolve.setNamespacePrefix(namespacePrefix);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public fflib_IAppBindingResolver byPackageName(String packageName)
|
|
||||||
{
|
|
||||||
this.bindingToResolve.setPackageName(packageName);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles lazy loading of modules, if no custom module is configured (via addModule) the default module is returned
|
* Handles lazy loading of modules, if no custom module is configured (via addModule) the default module is returned
|
||||||
*
|
*
|
||||||
|
|||||||
-21
@@ -33,25 +33,4 @@ public abstract class fflib_DynamicAppFactory
|
|||||||
protected String packageName;
|
protected String packageName;
|
||||||
|
|
||||||
protected fflib_IAppBindingResolver resolver;
|
protected fflib_IAppBindingResolver resolver;
|
||||||
protected Map<System.Type, System.Type> routes;
|
|
||||||
|
|
||||||
protected Map<Object, Object> mockImplByObjectType = new Map<Object, Object>();
|
|
||||||
|
|
||||||
protected void setMock(Object objectType, Object mock)
|
|
||||||
{
|
|
||||||
this.mockImplByObjectType.put(
|
|
||||||
objectType,
|
|
||||||
mock
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Object getMock(Object objectType)
|
|
||||||
{
|
|
||||||
return this.mockImplByObjectType.get(objectType);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Boolean hasMock(Object objectType)
|
|
||||||
{
|
|
||||||
return this.mockImplByObjectType.containsKey(objectType);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
-6
@@ -31,11 +31,5 @@
|
|||||||
public interface fflib_IAppBindingResolver
|
public interface fflib_IAppBindingResolver
|
||||||
{
|
{
|
||||||
fflib_IAppBindingResolver addModule(fflib_IAppBindingModule bindingModule);
|
fflib_IAppBindingResolver addModule(fflib_IAppBindingModule bindingModule);
|
||||||
fflib_IAppBindingResolver byObject(Object bindingObject);
|
|
||||||
fflib_IAppBindingResolver bySequence(Integer sequence);
|
|
||||||
fflib_IAppBindingResolver byType(fflib_AppBindingType bindingType);
|
|
||||||
fflib_IAppBindingResolver byInterfaceType(System.Type interfaceType);
|
|
||||||
fflib_IAppBindingResolver byNamespacePrefix(String namespacePrefix);
|
|
||||||
fflib_IAppBindingResolver byPackageName(String packageName);
|
|
||||||
List<fflib_IAppBinding> resolve();
|
List<fflib_IAppBinding> resolve();
|
||||||
}
|
}
|
||||||
-121
@@ -1,121 +0,0 @@
|
|||||||
/**
|
|
||||||
* File Name: fflib_SObjectShareSelector
|
|
||||||
*
|
|
||||||
* @description Abstract selector for SObject Shares
|
|
||||||
*
|
|
||||||
* @author architect ir. Wilhelmus G.J. Velzeboer
|
|
||||||
*
|
|
||||||
* Copyright (c), W.G.J. Velzeboer,
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
|
||||||
* are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* - Redistributions of source code must retain the above author notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* - Neither the name of the author nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this software without
|
|
||||||
* specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
||||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
||||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
||||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
public abstract inherited sharing class fflib_SObjectShareSelector
|
|
||||||
extends fflib_SObjectSelector
|
|
||||||
{
|
|
||||||
private String accessLevelFieldName
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (accessLevelFieldName == null)
|
|
||||||
{
|
|
||||||
accessLevelFieldName = fflib_SObjectShare.getAccessLevelFieldName(getSObjectType2());
|
|
||||||
}
|
|
||||||
return accessLevelFieldName;
|
|
||||||
}
|
|
||||||
private set;
|
|
||||||
}
|
|
||||||
private String parentIdFieldName
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (parentIdFieldName == null)
|
|
||||||
{
|
|
||||||
parentIdFieldName = fflib_SObjectShare.getParentIdFieldName(getSObjectType2());
|
|
||||||
}
|
|
||||||
return parentIdFieldName;
|
|
||||||
}
|
|
||||||
private set;
|
|
||||||
}
|
|
||||||
private String rowCauseFieldName = 'RowCause';
|
|
||||||
private String userOrGroupIdName = 'UserOrGroupId';
|
|
||||||
private List<Schema.SObjectField> sObjectFieldList
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (sObjectFieldList == null)
|
|
||||||
{
|
|
||||||
SObjectType sObjectType = getSObjectType2();
|
|
||||||
fflib_SObjectDescribe sObjectDescribe = fflib_SObjectDescribe.getDescribe(sObjectType);
|
|
||||||
sObjectFieldList = new List<Schema.SObjectField>
|
|
||||||
{
|
|
||||||
fflib_SObjectShare.getIdField(sObjectType),
|
|
||||||
fflib_SObjectShare.getAccessLevelField(sObjectType),
|
|
||||||
fflib_SObjectShare.getParentIdField(sObjectType),
|
|
||||||
fflib_SObjectShare.getRowCauseField(sObjectType),
|
|
||||||
fflib_SObjectShare.getUserOrGroupIdField(sObjectType)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return sObjectFieldList;
|
|
||||||
}
|
|
||||||
private set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Schema.SObjectField> getSObjectFieldList()
|
|
||||||
{
|
|
||||||
return sObjectFieldList;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<SObject> selectShareByParentId(Set<Id> parentIds)
|
|
||||||
{
|
|
||||||
return Database.query(
|
|
||||||
newQueryFactory()
|
|
||||||
.setCondition(parentIdFieldName + ' IN :parentIds')
|
|
||||||
.toSOQL());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<SObject> selectShareByParentId(Set<Id> parentIds, Set<Id> userOrGroupIds)
|
|
||||||
{
|
|
||||||
return Database.query(
|
|
||||||
newQueryFactory()
|
|
||||||
.setCondition(parentIdFieldName + ' IN :parentIds AND ' + userOrGroupIdName + ' IN :userOrGroupIds')
|
|
||||||
.toSOQL());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<SObject> selectShareByParentId(Set<Id> parentIds, Set<Id> userOrGroupIds, Set<String> accessLevels)
|
|
||||||
{
|
|
||||||
return Database.query(
|
|
||||||
newQueryFactory()
|
|
||||||
.setCondition(parentIdFieldName + ' IN :parentIds AND '
|
|
||||||
+ userOrGroupIdName + ' IN :userOrGroupIds AND '
|
|
||||||
+ accessLevelFieldName + ' IN :accessLevels')
|
|
||||||
.toSOQL());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<SObject> selectShareByParentId(Set<Id> parentIds, Set<String> rowCauses)
|
|
||||||
{
|
|
||||||
return Database.query(
|
|
||||||
newQueryFactory()
|
|
||||||
.setCondition(parentIdFieldName + ' IN :parentIds AND ' + rowCauseFieldName + ' IN :rowCauses')
|
|
||||||
.toSOQL());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-2
@@ -42,9 +42,9 @@ public virtual with sharing class fflib_SObjectTriggerHandler
|
|||||||
super(records, sObjectType);
|
super(records, sObjectType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SObject> getChangedRecords(String fileName)
|
public List<SObject> getChangedRecords(String fieldName)
|
||||||
{
|
{
|
||||||
return getChangedRecords(new Set<String>{ fileName });
|
return getChangedRecords(new Set<String>{ fieldName });
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SObject> getChangedRecords(Schema.SObjectField fieldToken)
|
public List<SObject> getChangedRecords(Schema.SObjectField fieldToken)
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public with sharing class fflib_SObjectShare
|
|||||||
Id parentId,
|
Id parentId,
|
||||||
Id userOrGroupId)
|
Id userOrGroupId)
|
||||||
{
|
{
|
||||||
return createShares(sObjectType, new Set<Id>{ parentId }, new Set<Id>{ userOrGroupId }, ACCESS_LEVEL_EDIT)
|
return createEditShares(sObjectType, parentId, new Set<Id>{ userOrGroupId })
|
||||||
.get(0);
|
.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ public with sharing class fflib_SObjectShare
|
|||||||
Id parentId,
|
Id parentId,
|
||||||
Set<Id> userOrGroupIds)
|
Set<Id> userOrGroupIds)
|
||||||
{
|
{
|
||||||
return createShares(sObjectType, new Set<Id>{ parentId }, userOrGroupIds, ACCESS_LEVEL_EDIT);
|
return createEditShares(sObjectType, new Set<Id>{ parentId }, userOrGroupIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,7 +98,7 @@ public with sharing class fflib_SObjectShare
|
|||||||
Id parentId,
|
Id parentId,
|
||||||
Id userOrGroupId)
|
Id userOrGroupId)
|
||||||
{
|
{
|
||||||
return createShares(sObjectType, new Set<Id>{ parentId }, new Set<Id>{ userOrGroupId }, ACCESS_LEVEL_READ)
|
return createReadShares(sObjectType, parentId, new Set<Id>{ userOrGroupId })
|
||||||
.get(0);
|
.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ public with sharing class fflib_SObjectShare
|
|||||||
Id parentId,
|
Id parentId,
|
||||||
Set<Id> userOrGroupIds)
|
Set<Id> userOrGroupIds)
|
||||||
{
|
{
|
||||||
return createShares(sObjectType, new Set<Id>{ parentId }, userOrGroupIds, ACCESS_LEVEL_READ);
|
return createReadShares(sObjectType, new Set<Id>{ parentId }, userOrGroupIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,17 +172,6 @@ public with sharing class fflib_SObjectShare
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the SObjectField for the Id field of the given SObjectType
|
|
||||||
*
|
|
||||||
* @param sObjectType The SObjectType to get its Id field
|
|
||||||
*
|
|
||||||
* @return Returns the Id.SObjectField
|
|
||||||
*/
|
|
||||||
public static SObjectField getIdField(SObjectType sObjectType)
|
|
||||||
{
|
|
||||||
return getsObjectField(fflib_SObjectDescribe.getDescribe(sObjectType).getFields(), 'Id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name of the AccessLevel field of the given SObjectType
|
* Gets the name of the AccessLevel field of the given SObjectType
|
||||||
|
|||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
@IsTest(IsParallel=true)
|
||||||
|
private class fflib_AppBindingMetaDataModuleTest
|
||||||
|
{
|
||||||
|
@IsTest
|
||||||
|
static void itShouldCheckForAnException(){
|
||||||
|
fflib_AppBindingMetaDataModule module = new fflib_AppBindingMetaDataModule();
|
||||||
|
fflib_AppBinding__mdt binding = new fflib_AppBinding__mdt(
|
||||||
|
BindingObjectAlternate__c = 'SomeNonExistingClass',
|
||||||
|
DeveloperName = 'SomeNonExistingClass'
|
||||||
|
);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
module.getBindingObject(binding);
|
||||||
|
System.Assert.fail('Expected an exception');
|
||||||
|
}
|
||||||
|
catch (fflib_AppBindingMetaDataModule.DeveloperException e)
|
||||||
|
{
|
||||||
|
System.Assert.areEqual(
|
||||||
|
e.getMessage(),
|
||||||
|
'Failed to find (S)Object somenonexistingclass referenced by binding SomeNonExistingClass'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@IsTest
|
||||||
|
static void getSystemType_failing(){
|
||||||
|
fflib_AppBindingMetaDataModule module = new fflib_AppBindingMetaDataModule();
|
||||||
|
fflib_AppBinding__mdt binding = new fflib_AppBinding__mdt(
|
||||||
|
ImplementationType__c = 'SomeNonExistingClass',
|
||||||
|
DeveloperName = 'SomeNonExistingClass'
|
||||||
|
);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
module.getSystemType(binding, fflib_AppBinding__mdt.ImplementationType__c);
|
||||||
|
System.Assert.fail('Expected an exception');
|
||||||
|
}
|
||||||
|
catch (fflib_AppBindingMetaDataModule.DeveloperException e)
|
||||||
|
{
|
||||||
|
System.Assert.areEqual(
|
||||||
|
e.getMessage(),
|
||||||
|
'Unable to find SomeNonExistingClass referenced by binding SomeNonExistingClass for ImplementationType__c'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
@IsTest(IsParallel=true)
|
||||||
|
private class fflib_AppBindingResolverTest
|
||||||
|
{
|
||||||
|
@IsTest
|
||||||
|
static void testWithEmptyRouter()
|
||||||
|
{
|
||||||
|
fflib_IAppBindingResolver resolver = fflib_AppBindingResolver.newInstance();
|
||||||
|
System.Assert.areEqual(0, resolver.resolve().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@IsTest
|
||||||
|
static void testWithCustomRouter(){
|
||||||
|
fflib_IAppBindingResolver resolver = new fflib_AppBindingResolver(new CustomRouter());
|
||||||
|
System.Assert.areEqual(0, resolver.resolve().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
private class CustomRouter implements fflib_IAppBindingRouter
|
||||||
|
{
|
||||||
|
public Map<Type, Type> getRoutes()
|
||||||
|
{
|
||||||
|
return new Map<Type, Type>{ fflib_AppBindingResolverTest.class => fflib_AppBindingResolverTest.class };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>57.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexClass>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
@IsTest
|
||||||
|
private class fflib_AppBindingsTest
|
||||||
|
{
|
||||||
|
@IsTest
|
||||||
|
static void testBehavior()
|
||||||
|
{
|
||||||
|
fflib_AppBinding binding = new fflib_AppBinding();
|
||||||
|
binding.setImplementationType(fflib_AppBindingsTest.class);
|
||||||
|
binding.setInterfaceType(fflib_AppBindingsTest.class);
|
||||||
|
binding.setBindingObject(fflib_AppBindingsTest.class);
|
||||||
|
binding.setNamespacePrefix('test');
|
||||||
|
binding.setSequence(1);
|
||||||
|
|
||||||
|
fflib_AppBindings appBindings = new fflib_AppBindings(new List<fflib_IAppBinding>());
|
||||||
|
appBindings.addBinding(binding);
|
||||||
|
System.Assert.areEqual(fflib_AppBindingsTest.class, appBindings.getImplementations().get(0), 'Incorrect returned implementation');
|
||||||
|
System.Assert.areEqual(1, appBindings.selectByInterfaceType(fflib_AppBindingsTest.class).getObjects().size(), 'Incorrect returned interface type');
|
||||||
|
System.Assert.areEqual(1, appBindings.selectByNamespacePrefix('test').getObjects().size(), 'Incorrect returned namespace prefix');
|
||||||
|
System.Assert.areEqual(1, appBindings.selectByObject(fflib_AppBindingsTest.class).getObjects().size(), 'Incorrect returned object');
|
||||||
|
System.Assert.areEqual(fflib_IAppBinding.class, appBindings.getType(), 'Incorrect returned type');
|
||||||
|
appBindings.selectBySequence(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>57.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexClass>
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
@IsTest(IsParallel=true)
|
||||||
|
private class fflib_ClassicSelectorFactoryTest
|
||||||
|
{
|
||||||
|
@IsTest
|
||||||
|
static void testSelectById()
|
||||||
|
{
|
||||||
|
fflib_ClassicSelectorFactory classicSelectorFactory =
|
||||||
|
new fflib_ClassicSelectorFactory(
|
||||||
|
new Map<SObjectType, Type> {Schema.Account.SObjectType => TestAccountSelector.class});
|
||||||
|
List<SObject> sObjects = classicSelectorFactory.selectById(
|
||||||
|
new Set<Id> {fflib_IDGenerator.generate(Schema.Account.SObjectType)},
|
||||||
|
Schema.Account.SObjectType);
|
||||||
|
System.Assert.isTrue(sObjects.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestAccountSelector implements fflib_ISObjectSelector
|
||||||
|
{
|
||||||
|
public List<SObject> selectSObjectsById(Set<Id> idSet)
|
||||||
|
{
|
||||||
|
return new List<SObject>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SObjectType sObjectType()
|
||||||
|
{
|
||||||
|
return Schema.Account.SObjectType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>57.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexClass>
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
@IsTest(IsParallel=true)
|
||||||
|
private class fflib_ClassicUnitOfWorkFactoryTest
|
||||||
|
{
|
||||||
|
@IsTest
|
||||||
|
static void testUnitOfWork()
|
||||||
|
{
|
||||||
|
new fflib_ClassicUnitOfWorkFactory(new List<SObjectType>{ Schema.Account.SObjectType });
|
||||||
|
}
|
||||||
|
|
||||||
|
@IsTest
|
||||||
|
static void testUnitOfWorkMock()
|
||||||
|
{
|
||||||
|
fflib_ApexMocks mocks = new fflib_ApexMocks();
|
||||||
|
fflib_ISObjectUnitOfWork unitOfWorkMock = new fflib_SObjectMocks.SObjectUnitOfWork(mocks);
|
||||||
|
|
||||||
|
new fflib_ClassicUnitOfWorkFactory()
|
||||||
|
.setMock(unitOfWorkMock);
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>57.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexClass>
|
||||||
+5
@@ -44,6 +44,11 @@ public class fflib_DynamicDomainFactoryTest
|
|||||||
fflib_DynamicSelectorFactoryTest.Selector,
|
fflib_DynamicSelectorFactoryTest.Selector,
|
||||||
PACKAGE_FORCE_APP);
|
PACKAGE_FORCE_APP);
|
||||||
|
|
||||||
|
private static final fflib_DynamicDomainFactory NonDomain =
|
||||||
|
new fflib_DynamicDomainFactory(
|
||||||
|
bindingResolver,
|
||||||
|
fflib_DynamicSelectorFactoryTest.Selector);
|
||||||
|
|
||||||
private static final fflib_DynamicDomainFactory OtherDomain =
|
private static final fflib_DynamicDomainFactory OtherDomain =
|
||||||
new fflib_DynamicDomainFactory(
|
new fflib_DynamicDomainFactory(
|
||||||
bindingResolver,
|
bindingResolver,
|
||||||
|
|||||||
+1
-1
@@ -88,7 +88,7 @@ private class fflib_LogEventStoreListenerTest
|
|||||||
{
|
{
|
||||||
Profile profile = [SELECT Id FROM Profile WHERE Name = :TEST_USER_PROFILE];
|
Profile profile = [SELECT Id FROM Profile WHERE Name = :TEST_USER_PROFILE];
|
||||||
return new User(
|
return new User(
|
||||||
Alias = 'Testfflib',
|
Alias = 'TestUser',
|
||||||
Email = 'TestUser@example.com',
|
Email = 'TestUser@example.com',
|
||||||
EmailEncodingKey = 'UTF-8',
|
EmailEncodingKey = 'UTF-8',
|
||||||
FirstName = 'Test',
|
FirstName = 'Test',
|
||||||
|
|||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
@IsTest(IsParallel=true)
|
||||||
|
private class fflib_SObjectTriggerHandlerTest
|
||||||
|
{
|
||||||
|
@IsTest
|
||||||
|
static void testNewRecords()
|
||||||
|
{
|
||||||
|
Account record = new Account(Name = 'Account');
|
||||||
|
List<Account> records = new List<Account> {record};
|
||||||
|
fflib_SObjectTriggerHandler handler = new fflib_SObjectTriggerHandler(records);
|
||||||
|
System.Assert.areEqual(0, handler.getChangedRecords('Name').size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@IsTest
|
||||||
|
static void testUpdateRecords()
|
||||||
|
{
|
||||||
|
Account record = new Account(
|
||||||
|
Id = fflib_IDGenerator.generate(Schema.Account.SObjectType),
|
||||||
|
Name = 'Account');
|
||||||
|
Account existingRecord = new Account(
|
||||||
|
Id = record.Id,
|
||||||
|
Name = '');
|
||||||
|
|
||||||
|
List<Account> records = new List<Account> {record};
|
||||||
|
fflib_SObjectTriggerHandler handler = new fflib_SObjectTriggerHandler(records, Schema.Account.SObjectType);
|
||||||
|
handler.ExistingRecords = new Map<Id, SObject>{ record.Id => existingRecord};
|
||||||
|
System.Assert.areEqual(1, handler.getChangedRecords(Schema.Account.Name).size());
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>57.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexClass>
|
||||||
+141
@@ -0,0 +1,141 @@
|
|||||||
|
@IsTest(IsParallel=true)
|
||||||
|
private class fflib_SObjectUnitOfWork2Test
|
||||||
|
{
|
||||||
|
private static List<SObjectType> SOBJECT_LIST = new List<SObjectType> {Schema.Account.SObjectType};
|
||||||
|
|
||||||
|
@IsTest
|
||||||
|
static void testRegisterNewOfDomain()
|
||||||
|
{
|
||||||
|
Account parentRecord = new Account(
|
||||||
|
Id = fflib_IDGenerator.generate(Schema.Account.SObjectType),
|
||||||
|
Name = 'Parent');
|
||||||
|
Account record = new Account(Name = 'Child');
|
||||||
|
List<Account> records = new List<Account> {record};
|
||||||
|
TestDomain domain = new TestDomain(records);
|
||||||
|
|
||||||
|
TestDML testDML = new TestDML();
|
||||||
|
fflib_SObjectUnitOfWork2 unitOfWork = new fflib_SObjectUnitOfWork2(SOBJECT_LIST, testDML);
|
||||||
|
unitOfWork.registerNew(domain, Schema.Account.ParentId, parentRecord);
|
||||||
|
unitOfWork.commitWork();
|
||||||
|
|
||||||
|
System.Assert.areEqual(1, testDML.toInsert.size(), 'Expected one record to be inserted');
|
||||||
|
System.Assert.areEqual(parentRecord.Id, ((Account) testDML.toInsert.get(0)).ParentId, 'Expected the record to be linked to the parent');
|
||||||
|
}
|
||||||
|
|
||||||
|
@IsTest
|
||||||
|
static void testRegisterDirtyOfDomain()
|
||||||
|
{
|
||||||
|
Account parentRecord = new Account(
|
||||||
|
Id = fflib_IDGenerator.generate(Schema.Account.SObjectType),
|
||||||
|
Name = 'Parent');
|
||||||
|
Account record = new Account(
|
||||||
|
Id = fflib_IDGenerator.generate(Schema.Account.SObjectType),
|
||||||
|
Name = 'Child');
|
||||||
|
List<Account> records = new List<Account> {record};
|
||||||
|
TestDomain domain = new TestDomain(records);
|
||||||
|
|
||||||
|
TestDML testDML = new TestDML();
|
||||||
|
fflib_SObjectUnitOfWork2 unitOfWork = new fflib_SObjectUnitOfWork2(SOBJECT_LIST, testDML);
|
||||||
|
unitOfWork.registerDirty(domain, Schema.Account.ParentId, parentRecord);
|
||||||
|
unitOfWork.commitWork();
|
||||||
|
|
||||||
|
System.Assert.areEqual(1, testDML.toUpdate.size(), 'Expected one record to be inserted');
|
||||||
|
System.Assert.areEqual(parentRecord.Id, ((Account) testDML.toUpdate.get(0)).ParentId, 'Expected the record to be linked to the parent');
|
||||||
|
}
|
||||||
|
|
||||||
|
@IsTest
|
||||||
|
static void testRegisterNewOfDomain_failing_NotTheSameType()
|
||||||
|
{
|
||||||
|
Account parentRecord = new Account(
|
||||||
|
Id = fflib_IDGenerator.generate(Schema.Account.SObjectType),
|
||||||
|
Name = 'Parent');
|
||||||
|
Account accountRecord = new Account(Name = 'Account');
|
||||||
|
Contact contactRecord = new Contact(LastName = 'Contact');
|
||||||
|
List<SObject> records = new List<SObject> {accountRecord, contactRecord};
|
||||||
|
|
||||||
|
TestDML testDML = new TestDML();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fflib_SObjectUnitOfWork2 unitOfWork = new fflib_SObjectUnitOfWork2(SOBJECT_LIST, testDML);
|
||||||
|
unitOfWork.registerNew(records, Schema.Account.ParentId, parentRecord);
|
||||||
|
System.Assert.fail('The UnitOfWork should have thrown an exception');
|
||||||
|
}
|
||||||
|
catch (fflib_SObjectUnitOfWork.UnitOfWorkException e)
|
||||||
|
{
|
||||||
|
System.Assert.areEqual(e.getMessage(), 'All records should be of the same SObjectType');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@IsTest
|
||||||
|
static void testRegisterNewOfDomain_failing_NotSupportedType()
|
||||||
|
{
|
||||||
|
Account parentRecord = new Account(
|
||||||
|
Id = fflib_IDGenerator.generate(Schema.Account.SObjectType),
|
||||||
|
Name = 'Parent');
|
||||||
|
Contact contactRecord = new Contact(LastName = 'Contact');
|
||||||
|
List<SObject> records = new List<SObject> {contactRecord};
|
||||||
|
|
||||||
|
TestDML testDML = new TestDML();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fflib_SObjectUnitOfWork2 unitOfWork = new fflib_SObjectUnitOfWork2(SOBJECT_LIST, testDML);
|
||||||
|
unitOfWork.registerNew(records, Schema.Account.ParentId, parentRecord);
|
||||||
|
System.Assert.fail('The UnitOfWork should have thrown an exception');
|
||||||
|
}
|
||||||
|
catch (fflib_SObjectUnitOfWork.UnitOfWorkException e)
|
||||||
|
{
|
||||||
|
System.Assert.areEqual(e.getMessage(), 'SObject type Contact is not supported by this unit of work');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestDomain extends fflib_SObjects
|
||||||
|
{
|
||||||
|
private TestDomain(List<SObject> records)
|
||||||
|
{
|
||||||
|
super(records);
|
||||||
|
}
|
||||||
|
|
||||||
|
private TestDomain(List<SObject> records, SObjectType sObjectType)
|
||||||
|
{
|
||||||
|
super(records, sObjectType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override SObjectType getSObjectType()
|
||||||
|
{
|
||||||
|
return Schema.Account.SObjectType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestDML implements fflib_SObjectUnitOfWork.IDML
|
||||||
|
{
|
||||||
|
public List<SObject> toDelete = new List<SObject>();
|
||||||
|
public List<SObject> toInsert = new List<SObject>();
|
||||||
|
public List<SObject> toUpdate = new List<SObject>();
|
||||||
|
public List<SObject> toEmptyRecycleBin = new List<SObject>();
|
||||||
|
public List<SObject> toPublish = new List<SObject>();
|
||||||
|
public void dmlDelete(List<SObject> objList)
|
||||||
|
{
|
||||||
|
this.toDelete.addAll(objList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dmlInsert(List<SObject> objList)
|
||||||
|
{
|
||||||
|
this.toInsert.addAll(objList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dmlUpdate(List<SObject> objList)
|
||||||
|
{
|
||||||
|
this.toUpdate.addAll(objList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void emptyRecycleBin(List<SObject> objList)
|
||||||
|
{
|
||||||
|
this.toEmptyRecycleBin.addAll(objList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void eventPublish(List<SObject> objList)
|
||||||
|
{
|
||||||
|
this.toPublish.addAll(objList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>57.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexClass>
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
@IsTest(IsParallel=true)
|
||||||
|
private class fflib_SObjectShareTest
|
||||||
|
{
|
||||||
|
@IsTest
|
||||||
|
static void testEditShareCreation_single()
|
||||||
|
{
|
||||||
|
Id accountId = fflib_IDGenerator.generate(Schema.Account.SObjectType);
|
||||||
|
Id groupId = fflib_IDGenerator.generate(Schema.Group.SObjectType);
|
||||||
|
SObject editShare = fflib_SObjectShare.createEditShare(Schema.Account.SObjectType, accountId, groupId);
|
||||||
|
System.Assert.areEqual(accountId, editShare.get('AccountId'));
|
||||||
|
System.Assert.areEqual(groupId, editShare.get('UserOrGroupId'));
|
||||||
|
System.Assert.areEqual('Edit', editShare.get('AccountAccessLevel'));
|
||||||
|
System.Assert.areEqual('Manual', editShare.get('RowCause'));
|
||||||
|
}
|
||||||
|
|
||||||
|
@IsTest
|
||||||
|
static void testReadShareCreation_single()
|
||||||
|
{
|
||||||
|
Id accountId = fflib_IDGenerator.generate(Schema.Account.SObjectType);
|
||||||
|
Id groupId = fflib_IDGenerator.generate(Schema.Group.SObjectType);
|
||||||
|
SObject editShare = fflib_SObjectShare.createReadShare(Schema.Account.SObjectType, accountId, groupId);
|
||||||
|
System.Assert.areEqual(accountId, editShare.get('AccountId'));
|
||||||
|
System.Assert.areEqual(groupId, editShare.get('UserOrGroupId'));
|
||||||
|
System.Assert.areEqual('Read', editShare.get('AccountAccessLevel'));
|
||||||
|
System.Assert.areEqual('Manual', editShare.get('RowCause'));
|
||||||
|
}
|
||||||
|
|
||||||
|
@IsTest
|
||||||
|
static void testAccessLevelField()
|
||||||
|
{
|
||||||
|
System.Assert.areEqual(
|
||||||
|
Schema.AccountShare.AccountAccessLevel,
|
||||||
|
fflib_SObjectShare.getAccessLevelField(Schema.AccountShare.SObjectType));
|
||||||
|
}
|
||||||
|
|
||||||
|
@IsTest
|
||||||
|
static void testParentIdField()
|
||||||
|
{
|
||||||
|
System.Assert.areEqual(
|
||||||
|
Schema.AccountShare.AccountId,
|
||||||
|
fflib_SObjectShare.getParentIdField(Schema.AccountShare.SObjectType));
|
||||||
|
}
|
||||||
|
|
||||||
|
@IsTest
|
||||||
|
static void testRowClauseField()
|
||||||
|
{
|
||||||
|
System.Assert.areEqual(
|
||||||
|
Schema.AccountShare.RowCause,
|
||||||
|
fflib_SObjectShare.getRowCauseField(Schema.AccountShare.SObjectType));
|
||||||
|
}
|
||||||
|
@IsTest
|
||||||
|
static void testUserOrGroupField()
|
||||||
|
{
|
||||||
|
System.Assert.areEqual(
|
||||||
|
Schema.AccountShare.UserOrGroupId,
|
||||||
|
fflib_SObjectShare.getUserOrGroupIdField(Schema.AccountShare.SObjectType));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||||
|
<apiVersion>57.0</apiVersion>
|
||||||
|
<status>Active</status>
|
||||||
|
</ApexClass>
|
||||||
Reference in New Issue
Block a user