Increase code coverage
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
mkdir ./temp
|
||||
mkdir ./temp || true
|
||||
cd ./temp
|
||||
rm -Rf fflib-apex-mocks/
|
||||
rm -Rf fflib-apex-common/
|
||||
|
||||
-5
@@ -32,11 +32,6 @@ public virtual class fflib_ClassicSelectorFactory
|
||||
extends fflib_Application.SelectorFactory
|
||||
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
|
||||
* 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)
|
||||
{
|
||||
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();
|
||||
|
||||
// Assume its an SObjectType
|
||||
List<Schema.DescribeSObjectResult> schemaDescribes = Schema.describeSObjects(new List<String> {bindingObjectApiName});
|
||||
if (schemaDescribes.size() == 1)
|
||||
try
|
||||
{
|
||||
List<Schema.DescribeSObjectResult> schemaDescribes = Schema.describeSObjects(new List<String> {bindingObjectApiName});
|
||||
return schemaDescribes.get(0).getSObjectType();
|
||||
}
|
||||
else
|
||||
catch (InvalidParameterValueException e)
|
||||
{
|
||||
// check if its an Object (class)
|
||||
Type objectType = System.Type.forName(bindingObjectApiName);
|
||||
@@ -93,6 +94,7 @@ public with sharing class fflib_AppBindingMetaDataModule
|
||||
return bindingTypeByStrings.get(binding.Type__c.toUpperCase());
|
||||
}
|
||||
|
||||
@TestVisible
|
||||
private Type getSystemType(fflib_AppBinding__mdt binding, Schema.SObjectField sObjectField)
|
||||
{
|
||||
String systemTypeName = String.valueOf(binding.get(sObjectField));
|
||||
|
||||
-36
@@ -96,42 +96,6 @@ public virtual class fflib_AppBindingResolver
|
||||
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
|
||||
*
|
||||
|
||||
-11
@@ -33,7 +33,6 @@ public abstract class fflib_DynamicAppFactory
|
||||
protected String packageName;
|
||||
|
||||
protected fflib_IAppBindingResolver resolver;
|
||||
protected Map<System.Type, System.Type> routes;
|
||||
|
||||
protected Map<Object, Object> mockImplByObjectType = new Map<Object, Object>();
|
||||
|
||||
@@ -44,14 +43,4 @@ public abstract class fflib_DynamicAppFactory
|
||||
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
|
||||
{
|
||||
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();
|
||||
}
|
||||
+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'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+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>
|
||||
+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>
|
||||
+1
-1
@@ -88,7 +88,7 @@ private class fflib_LogEventStoreListenerTest
|
||||
{
|
||||
Profile profile = [SELECT Id FROM Profile WHERE Name = :TEST_USER_PROFILE];
|
||||
return new User(
|
||||
Alias = 'Testfflib',
|
||||
Alias = 'TestUser',
|
||||
Email = 'TestUser@example.com',
|
||||
EmailEncodingKey = 'UTF-8',
|
||||
FirstName = 'Test',
|
||||
|
||||
Reference in New Issue
Block a user