@@ -40,40 +40,40 @@ private with sharing class fflib_SObjectUnitOfWorkTest
4040 {
4141 // Insert Opporunities with UnitOfWork
4242 {
43- fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork (MY_SOBJECTS );
43+ fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork (MY_SOBJECTS );
4444 for (Integer o = 0 ; o < 10 ; o ++ )
4545 {
4646 Opportunity opp = new Opportunity ();
4747 opp .Name = ' UoW Test Name ' + o ;
4848 opp .StageName = ' Open' ;
4949 opp .CloseDate = System .today ();
50- uow .registerNew (opp );
50+ uow .registerNew (new List < SObject >{ opp });
5151 for (Integer i = 0 ; i < o + 1 ; i ++ )
52- {
52+ {
5353 Product2 product = new Product2 ();
5454 product .Name = opp .Name + ' : Product : ' + i ;
55- uow .registerNew (product );
55+ uow .registerNew (new List < SObject >{ product });
5656 PricebookEntry pbe = new PricebookEntry ();
5757 pbe .UnitPrice = 10 ;
5858 pbe .IsActive = true ;
5959 pbe .UseStandardPrice = false ;
6060 pbe .Pricebook2Id = Test .getStandardPricebookId ();
61- uow .registerNew (pbe , PricebookEntry .Product2Id , product );
61+ uow .registerNew (pbe , PricebookEntry .Product2Id , product );
6262 OpportunityLineItem oppLineItem = new OpportunityLineItem ();
6363 oppLineItem .Quantity = 1 ;
6464 oppLineItem .TotalPrice = 10 ;
6565 uow .registerRelationship (oppLineItem , OpportunityLineItem .PricebookEntryId , pbe );
6666 uow .registerNew (oppLineItem , OpportunityLineItem .OpportunityId , opp );
6767 }
68- }
68+ }
6969 uow .commitWork ();
7070 }
7171
7272 // Assert Results
7373 assertResults (' UoW' );
7474 // TODO: Need to re-instate this check with a better approach, as it is not possible when
7575 // product triggers contribute to DML (e.g. in sample app Opportunity trigger)
76- // System.assertEquals(5 /* Oddly a setSavePoint consumes a DML */, Limits.getDmlStatements());
76+ // System.assertEquals(5 /* Oddly a setSavePoint consumes a DML */, Limits.getDmlStatements());
7777
7878 // Records to update
7979 List <Opportunity > opps = [select Id , Name , (Select Id from OpportunityLineItems ) from Opportunity where Name like ' UoW Test Name %' order by Name ];
@@ -82,11 +82,11 @@ private with sharing class fflib_SObjectUnitOfWorkTest
8282 {
8383 fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork (MY_SOBJECTS );
8484 Opportunity opp = opps [0 ];
85- opp .Name = opp .Name + ' Changed' ;
86- uow .registerDirty (opp );
85+ opp .Name = opp .Name + ' Changed' ;
86+ uow .registerDirty (new List < SObject >{ opp });
8787 Product2 product = new Product2 ();
8888 product .Name = opp .Name + ' : New Product' ;
89- uow .registerNew (product );
89+ uow .registerNew (new List < SObject >{ product });
9090 PricebookEntry pbe = new PricebookEntry ();
9191 pbe .UnitPrice = 10 ;
9292 pbe .IsActive = true ;
@@ -97,21 +97,21 @@ private with sharing class fflib_SObjectUnitOfWorkTest
9797 newOppLineItem .Quantity = 1 ;
9898 newOppLineItem .TotalPrice = 10 ;
9999 uow .registerRelationship (newOppLineItem , OpportunityLineItem .PricebookEntryId , pbe );
100- uow .registerNew (newOppLineItem , OpportunityLineItem .OpportunityId , opp );
100+ uow .registerNew (newOppLineItem , OpportunityLineItem .OpportunityId , opp );
101101 OpportunityLineItem existingOppLine = opp .OpportunityLineItems [0 ];
102102 // Test that operations on the same object can be daisy chained, and the same object registered as dirty more than once
103103 // This verifies that using a Map to back the dirty records collection prevents duplicate registration.
104104 existingOppLine .Quantity = 2 ;
105- uow .registerDirty (existingOppLine );
105+ uow .registerDirty (new List < SObject >{ existingOppLine } );
106106 existingOppLine .TotalPrice = 20 ;
107- uow .registerDirty (existingOppLine );
107+ uow .registerDirty (new List < SObject >{ existingOppLine } );
108108 uow .commitWork ();
109109 }
110110
111111 // Assert Results
112112 // TODO: Need to re-instate this check with a better approach, as it is not possible when
113- // product triggers contribute to DML (e.g. in sample app Opportunity trigger)
114- // System.assertEquals(11, Limits.getDmlStatements());
113+ // product triggers contribute to DML (e.g. in sample app Opportunity trigger)
114+ // System.assertEquals(11, Limits.getDmlStatements());
115115 opps = [select Id , Name , (Select Id , PricebookEntry .Product2 .Name , Quantity , TotalPrice from OpportunityLineItems Order By PricebookEntry .Product2 .Name ) from Opportunity where Name like ' UoW Test Name %' order by Name ];
116116 System .assertEquals (10 , opps .size ());
117117 System .assertEquals (' UoW Test Name 0 Changed' , opps [0 ].Name );
@@ -124,27 +124,27 @@ private with sharing class fflib_SObjectUnitOfWorkTest
124124 // Delete some records with the UnitOfWork
125125 {
126126 fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork (MY_SOBJECTS );
127- uow .registerDeleted (opps [0 ].OpportunityLineItems [1 ].PricebookEntry .Product2 ); // Delete PricebookEntry Product
128- uow .registerDeleted (opps [0 ].OpportunityLineItems [1 ].PricebookEntry ); // Delete PricebookEntry
129- uow .registerDeleted (opps [0 ].OpportunityLineItems [1 ]); // Delete OpportunityLine Item
127+ uow .registerDeleted (new List < SObject >{ opps [0 ].OpportunityLineItems [1 ].PricebookEntry .Product2 } ); // Delete PricebookEntry Product
128+ uow .registerDeleted (new List < SObject >{ opps [0 ].OpportunityLineItems [1 ].PricebookEntry } ); // Delete PricebookEntry
129+ uow .registerDeleted (new List < SObject >{ opps [0 ].OpportunityLineItems [1 ]} ); // Delete OpportunityLine Item
130130 // Register the same deletions more than once.
131131 // This verifies that using a Map to back the deleted records collection prevents duplicate registration.
132- uow .registerDeleted (opps [0 ].OpportunityLineItems [1 ].PricebookEntry .Product2 ); // Delete PricebookEntry Product
133- uow .registerDeleted (opps [0 ].OpportunityLineItems [1 ].PricebookEntry ); // Delete PricebookEntry
134- uow .registerDeleted (opps [0 ].OpportunityLineItems [1 ]); // Delete OpportunityLine Item
132+ uow .registerDeleted (new List < SObject >{ opps [0 ].OpportunityLineItems [1 ].PricebookEntry .Product2 } ); // Delete PricebookEntry Product
133+ uow .registerDeleted (new List < SObject >{ opps [0 ].OpportunityLineItems [1 ].PricebookEntry } ); // Delete PricebookEntry
134+ uow .registerDeleted (new List < SObject >{ opps [0 ].OpportunityLineItems [1 ]} ); // Delete OpportunityLine Item
135135 uow .commitWork ();
136- }
136+ }
137137
138138 // Assert Results
139139 // TODO: Need to re-instate this check with a better approach, as it is not possible when
140- // product triggers contribute to DML (e.g. in sample app Opportunity trigger)
141- // System.assertEquals(15, Limits.getDmlStatements());
140+ // product triggers contribute to DML (e.g. in sample app Opportunity trigger)
141+ // System.assertEquals(15, Limits.getDmlStatements());
142142 opps = [select Id , Name , (Select Id , PricebookEntry .Product2 .Name , Quantity from OpportunityLineItems Order By PricebookEntry .Product2 .Name ) from Opportunity where Name like ' UoW Test Name %' order by Name ];
143143 List <Product2 > prods = [Select Id from Product2 where Name = ' UoW Test Name 0 Changed : New Product' ];
144144 System .assertEquals (10 , opps .size ());
145145 System .assertEquals (' UoW Test Name 0 Changed' , opps [0 ].Name );
146146 System .assertEquals (1 , opps [0 ].OpportunityLineItems .size ()); // Should have deleted OpportunityLineItem added above
147- System .assertEquals (0 , prods .size ()); // Should have deleted Product added above
147+ System .assertEquals (0 , prods .size ()); // Should have deleted Product added above
148148 }
149149
150150 private static void assertResults (String prefix )
@@ -153,15 +153,15 @@ private with sharing class fflib_SObjectUnitOfWorkTest
153153 String filter = prefix + ' Test Name %' ;
154154 List <Opportunity > opps = [select Id , Name , (Select Id from OpportunityLineItems ) from Opportunity where Name like :filter order by Name ];
155155 System .assertEquals (10 , opps .size ());
156- System .assertEquals (1 , opps [0 ].OpportunityLineItems .size ());
157- System .assertEquals (2 , opps [1 ].OpportunityLineItems .size ());
158- System .assertEquals (3 , opps [2 ].OpportunityLineItems .size ());
159- System .assertEquals (4 , opps [3 ].OpportunityLineItems .size ());
160- System .assertEquals (5 , opps [4 ].OpportunityLineItems .size ());
161- System .assertEquals (6 , opps [5 ].OpportunityLineItems .size ());
162- System .assertEquals (7 , opps [6 ].OpportunityLineItems .size ());
163- System .assertEquals (8 , opps [7 ].OpportunityLineItems .size ());
164- System .assertEquals (9 , opps [8 ].OpportunityLineItems .size ());
165- System .assertEquals (10 , opps [9 ].OpportunityLineItems .size ());
156+ System .assertEquals (1 , opps [0 ].OpportunityLineItems .size ());
157+ System .assertEquals (2 , opps [1 ].OpportunityLineItems .size ());
158+ System .assertEquals (3 , opps [2 ].OpportunityLineItems .size ());
159+ System .assertEquals (4 , opps [3 ].OpportunityLineItems .size ());
160+ System .assertEquals (5 , opps [4 ].OpportunityLineItems .size ());
161+ System .assertEquals (6 , opps [5 ].OpportunityLineItems .size ());
162+ System .assertEquals (7 , opps [6 ].OpportunityLineItems .size ());
163+ System .assertEquals (8 , opps [7 ].OpportunityLineItems .size ());
164+ System .assertEquals (9 , opps [8 ].OpportunityLineItems .size ());
165+ System .assertEquals (10 , opps [9 ].OpportunityLineItems .size ());
166166 }
167167}
0 commit comments