diff --git a/dev-tools/update-dependencies b/dev-tools/update-dependencies index 3eeec3b..9bc0a96 100755 --- a/dev-tools/update-dependencies +++ b/dev-tools/update-dependencies @@ -1,6 +1,6 @@ #!/bin/bash -mkdir ./temp +mkdir ./temp || true cd ./temp rm -Rf fflib-apex-mocks/ rm -Rf fflib-apex-common/ diff --git a/sfdx-source/apex-extensions/main/application/classic/classes/fflib_ClassicSelectorFactory.cls b/sfdx-source/apex-extensions/main/application/classic/classes/fflib_ClassicSelectorFactory.cls index 0f6cd20..45ec345 100644 --- a/sfdx-source/apex-extensions/main/application/classic/classes/fflib_ClassicSelectorFactory.cls +++ b/sfdx-source/apex-extensions/main/application/classic/classes/fflib_ClassicSelectorFactory.cls @@ -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 diff --git a/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_AppBindingMetaDataModule.cls b/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_AppBindingMetaDataModule.cls index 601accb..ef569fb 100644 --- a/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_AppBindingMetaDataModule.cls +++ b/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_AppBindingMetaDataModule.cls @@ -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 schemaDescribes = Schema.describeSObjects(new List {bindingObjectApiName}); - if (schemaDescribes.size() == 1) + try { + List schemaDescribes = Schema.describeSObjects(new List {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)); diff --git a/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_AppBindingResolver.cls b/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_AppBindingResolver.cls index 7f65040..0991c2f 100644 --- a/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_AppBindingResolver.cls +++ b/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_AppBindingResolver.cls @@ -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 * diff --git a/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_DynamicAppFactory.cls b/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_DynamicAppFactory.cls index 7f7f742..73b0ae1 100644 --- a/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_DynamicAppFactory.cls +++ b/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_DynamicAppFactory.cls @@ -33,7 +33,6 @@ public abstract class fflib_DynamicAppFactory protected String packageName; protected fflib_IAppBindingResolver resolver; - protected Map routes; protected Map mockImplByObjectType = new Map(); @@ -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); - } } \ No newline at end of file diff --git a/sfdx-source/apex-extensions/main/application/dynamic/classes/interfaces/fflib_IAppBindingResolver.cls b/sfdx-source/apex-extensions/main/application/dynamic/classes/interfaces/fflib_IAppBindingResolver.cls index 3748dcc..21377f7 100644 --- a/sfdx-source/apex-extensions/main/application/dynamic/classes/interfaces/fflib_IAppBindingResolver.cls +++ b/sfdx-source/apex-extensions/main/application/dynamic/classes/interfaces/fflib_IAppBindingResolver.cls @@ -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 resolve(); } \ No newline at end of file diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingMetaDataModuleTest.cls b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingMetaDataModuleTest.cls new file mode 100644 index 0000000..ea4b070 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingMetaDataModuleTest.cls @@ -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' + ); + } + } +} \ No newline at end of file diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingMetaDataModuleTest.cls-meta.xml b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingMetaDataModuleTest.cls-meta.xml new file mode 100644 index 0000000..754ecb1 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingMetaDataModuleTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 57.0 + Active + diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingResolverTest.cls b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingResolverTest.cls new file mode 100644 index 0000000..84a6af8 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingResolverTest.cls @@ -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 getRoutes() + { + return new Map{ fflib_AppBindingResolverTest.class => fflib_AppBindingResolverTest.class }; + } + } +} \ No newline at end of file diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingResolverTest.cls-meta.xml b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingResolverTest.cls-meta.xml new file mode 100644 index 0000000..754ecb1 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingResolverTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 57.0 + Active + diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingsTest.cls b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingsTest.cls new file mode 100644 index 0000000..33536ea --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingsTest.cls @@ -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()); + 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); + } +} \ No newline at end of file diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingsTest.cls-meta.xml b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingsTest.cls-meta.xml new file mode 100644 index 0000000..754ecb1 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingsTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 57.0 + Active + diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicSelectorFactoryTest.cls b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicSelectorFactoryTest.cls new file mode 100644 index 0000000..70f6506 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicSelectorFactoryTest.cls @@ -0,0 +1,29 @@ + +@IsTest(IsParallel=true) +private class fflib_ClassicSelectorFactoryTest +{ + @IsTest + static void testSelectById() + { + fflib_ClassicSelectorFactory classicSelectorFactory = + new fflib_ClassicSelectorFactory( + new Map {Schema.Account.SObjectType => TestAccountSelector.class}); + List sObjects = classicSelectorFactory.selectById( + new Set {fflib_IDGenerator.generate(Schema.Account.SObjectType)}, + Schema.Account.SObjectType); + System.Assert.isTrue(sObjects.isEmpty()); + } + + private class TestAccountSelector implements fflib_ISObjectSelector + { + public List selectSObjectsById(Set idSet) + { + return new List(); + } + + public SObjectType sObjectType() + { + return Schema.Account.SObjectType; + } + } +} \ No newline at end of file diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicSelectorFactoryTest.cls-meta.xml b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicSelectorFactoryTest.cls-meta.xml new file mode 100644 index 0000000..754ecb1 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicSelectorFactoryTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 57.0 + Active + diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicUnitOfWorkFactoryTest.cls b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicUnitOfWorkFactoryTest.cls new file mode 100644 index 0000000..0fa6b03 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicUnitOfWorkFactoryTest.cls @@ -0,0 +1,19 @@ +@IsTest(IsParallel=true) +private class fflib_ClassicUnitOfWorkFactoryTest +{ + @IsTest + static void testUnitOfWork() + { + new fflib_ClassicUnitOfWorkFactory(new List{ 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); + } +} \ No newline at end of file diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicUnitOfWorkFactoryTest.cls-meta.xml b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicUnitOfWorkFactoryTest.cls-meta.xml new file mode 100644 index 0000000..754ecb1 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicUnitOfWorkFactoryTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 57.0 + Active + diff --git a/sfdx-source/apex-extensions/tests/classes/logger/fflib_LogEventStoreListenerTest.cls b/sfdx-source/apex-extensions/tests/classes/logger/fflib_LogEventStoreListenerTest.cls index d96903e..5a26e3f 100644 --- a/sfdx-source/apex-extensions/tests/classes/logger/fflib_LogEventStoreListenerTest.cls +++ b/sfdx-source/apex-extensions/tests/classes/logger/fflib_LogEventStoreListenerTest.cls @@ -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',