forked from apex-enterprise-patterns/fflib-apex-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed the ortoo_FabricatedSObject - have to accept that the library…
… is bespoke Added tests for the DirectedGraph and the new ObjectDescriber methods
- Loading branch information
1 parent
ca66375
commit 918873c
Showing
8 changed files
with
248 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
184 changes: 184 additions & 0 deletions
184
framework/default/ortoo-core/default/classes/utils/tests/DirectedGraphTest.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
@isTest | ||
private without sharing class DirectedGraphTest | ||
{ | ||
@isTest | ||
private static void generateSorted_whenASimpleGraphIsSpecified_willReturnTheNodesInOrder() // NOPMD: Test method name format | ||
{ | ||
DirectedGraph graph = new DirectedGraph() | ||
.addNode( 'Great grandparent' ) | ||
.addNode( 'Grandparent' ) | ||
.addNode( 'Parent' ) | ||
.addNode( 'Child' ) | ||
.addRelationship( 'Child', 'Parent' ) | ||
.addRelationship( 'Parent', 'Grandparent') | ||
.addRelationship( 'Grandparent', 'Great grandparent' ); | ||
|
||
List<Object> expectedNodes = new List<Object> | ||
{ | ||
'Child', | ||
'Parent', | ||
'Grandparent', | ||
'Great grandparent' | ||
}; | ||
|
||
List<Object> returnedNodes = graph.generateSorted(); | ||
|
||
System.assertEquals( expectedNodes, returnedNodes, 'generateSorted, when a simple graph has been built, will return the nodes in child to parent order' ); | ||
} | ||
|
||
@isTest | ||
private static void generateSorted_whenAComplexGraphIsSpecified_willReturnTheNodesInOrder() // NOPMD: Test method name format | ||
{ | ||
DirectedGraph graph = new DirectedGraph() | ||
.addNode( 'Great grandparent' ) | ||
.addNode( 'Grandparent of both parents' ) | ||
.addNode( 'Parent 1' ) | ||
.addNode( 'Parent 2' ) | ||
.addNode( 'Child 1 of Parent 1' ) | ||
.addNode( 'Child 2 of Parent 1' ) | ||
.addNode( 'Child 1 of Parent 2' ) | ||
.addNode( 'Child 2 of Parent 2' ) | ||
.addNode( 'Child of Parents 1 and 2' ) | ||
|
||
.addRelationship( 'Grandparent of both parents', 'Great grandparent' ) | ||
.addRelationship( 'Parent 1', 'Grandparent of both parents' ) | ||
.addRelationship( 'Parent 2', 'Grandparent of both parents' ) | ||
.addRelationship( 'Child 1 of Parent 1', 'Parent 1' ) | ||
.addRelationship( 'Child 2 of Parent 1', 'Parent 1' ) | ||
.addRelationship( 'Child 1 of Parent 2', 'Parent 2' ) | ||
.addRelationship( 'Child 2 of Parent 2', 'Parent 2' ) | ||
.addRelationship( 'Child of Parents 1 and 2', 'Parent 1') | ||
.addRelationship( 'Child of Parents 1 and 2', 'Parent 2' ); | ||
|
||
List<Object> expectedNodes = new List<Object> | ||
{ | ||
'Child 1 of Parent 1', | ||
'Child 2 of Parent 1', | ||
'Child 1 of Parent 2', | ||
'Child 2 of Parent 2', | ||
'Child of Parents 1 and 2', | ||
'Parent 1', | ||
'Parent 2', | ||
'Grandparent of both parents', | ||
'Great grandparent' | ||
}; | ||
|
||
List<Object> returnedNodes = graph.generateSorted(); | ||
|
||
System.assertEquals( expectedNodes, returnedNodes, 'generateSorted, when a complex graph has been built, will return the nodes in child to parent order' ); | ||
} | ||
|
||
@isTest | ||
private static void generateSorted_whenNoGraphIsSpecified_willReturnAnEmptyList() // NOPMD: Test method name format | ||
{ | ||
DirectedGraph graph = new DirectedGraph(); | ||
List<Object> expectedNodes = new List<Object>(); | ||
|
||
List<Object> returnedNodes = graph.generateSorted(); | ||
|
||
System.assertEquals( expectedNodes, returnedNodes, 'generateSorted, when no graph has been built, will return the an empty list' ); | ||
} | ||
|
||
@isTest | ||
private static void generateSorted_whenADuplicatedNodesAreSpecified_willReturnTheUniqueNodesInOrder() // NOPMD: Test method name format | ||
{ | ||
DirectedGraph graph = new DirectedGraph() | ||
.addNode( 'Great grandparent' ) | ||
.addNode( 'Great grandparent' ) | ||
.addNode( 'Great grandparent' ) | ||
.addNode( 'Grandparent' ) | ||
.addNode( 'Grandparent' ) | ||
.addNode( 'Grandparent' ) | ||
.addNode( 'Parent' ) | ||
.addNode( 'Parent' ) | ||
.addNode( 'Child' ) | ||
.addNode( 'Child' ) | ||
.addNode( 'Child' ) | ||
.addNode( 'Child' ) | ||
.addNode( 'Child' ) | ||
.addRelationship( 'Child', 'Parent' ) | ||
.addRelationship( 'Child', 'Parent' ) | ||
.addRelationship( 'Child', 'Parent' ) | ||
.addRelationship( 'Child', 'Parent' ) | ||
.addRelationship( 'Parent', 'Grandparent') | ||
.addRelationship( 'Parent', 'Grandparent') | ||
.addRelationship( 'Grandparent', 'Great grandparent' ); | ||
|
||
List<Object> expectedNodes = new List<Object> | ||
{ | ||
'Child', | ||
'Parent', | ||
'Grandparent', | ||
'Great grandparent' | ||
}; | ||
|
||
List<Object> returnedNodes = graph.generateSorted(); | ||
|
||
System.assertEquals( expectedNodes, returnedNodes, 'generateSorted, when duplicate nodes and relationships are specified, will return the unique nodes in child to parent order' ); | ||
} | ||
|
||
@isTest | ||
private static void generateSorted_whenACircularReference_willThrowAnException() // NOPMD: Test method name format | ||
{ | ||
DirectedGraph graph = new DirectedGraph() | ||
.addNode( 1 ) | ||
.addNode( 2 ) | ||
.addNode( 3 ) | ||
.addRelationship( 1, 2 ) | ||
.addRelationship( 2, 3 ) | ||
.addRelationship( 3, 1 ); | ||
Test.startTest(); | ||
String exceptionMessage; | ||
try | ||
{ | ||
graph.generateSorted(); | ||
} | ||
catch ( Exception e ) | ||
{ | ||
exceptionMessage = e.getMessage(); | ||
} | ||
Test.stopTest(); | ||
|
||
Amoss_Asserts.assertContains( 'The graph contains a circular reference and therefore cannot be resolved', exceptionMessage, 'generateSorted, when a circular reference has been defined, will throw an exception' ); | ||
} | ||
|
||
@isTest | ||
private static void addRelationship_whenGivenAnInvalidChild_willThrowAnException() // NOPMD: Test method name format | ||
{ | ||
DirectedGraph graph = new DirectedGraph() | ||
.addNode( 'Parent' ); | ||
Test.startTest(); | ||
String exceptionMessage; | ||
try | ||
{ | ||
graph.addRelationship( 'UnregisteredChild', 'Parent' ); | ||
} | ||
catch ( Exception e ) | ||
{ | ||
exceptionMessage = e.getMessage(); | ||
} | ||
Test.stopTest(); | ||
|
||
Amoss_Asserts.assertContains( 'addRelationship called with a child that has not been added as a node (UnregisteredChild)', exceptionMessage, 'addRelationship, when given a child that has not previously been added, will throw an exception' ); | ||
} | ||
|
||
@isTest | ||
private static void addRelationship_whenGivenAnInvalidParent_willThrowAnException() // NOPMD: Test method name format | ||
{ | ||
DirectedGraph graph = new DirectedGraph() | ||
.addNode( 'Child' ); | ||
Test.startTest(); | ||
String exceptionMessage; | ||
try | ||
{ | ||
graph.addRelationship( 'Child', 'UnregisteredParent' ); | ||
} | ||
catch ( Exception e ) | ||
{ | ||
exceptionMessage = e.getMessage(); | ||
} | ||
Test.stopTest(); | ||
|
||
Amoss_Asserts.assertContains( 'addRelationship called with a parent that has not been added as a node (UnregisteredParent)', exceptionMessage, 'addRelationship, when given a parent that has not previously been added, will throw an exception' ); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...sses/ortoo_FabricatedSObject.cls-meta.xml → ...tils/tests/DirectedGraphTest.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>53.0</apiVersion> | ||
<apiVersion>52.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
26 changes: 0 additions & 26 deletions
26
framework/default/sobject-fabricator-extensions/classes/ortoo_FabricatedSObject.cls
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters