@@ -339,27 +339,27 @@ private with sharing class fflib_SObjectUnitOfWorkTest
339339 }
340340
341341 /**
342- * Try registering two instances of the same record as dirty.
342+ * Try registering two instances of the same record as dirty. Second register should overwrite first.
343343 *
344344 * Testing:
345345 *
346346 * - Exception is thrown stopping second registration
347347 */
348348 @isTest
349- private static void testRegisterDirty_DoubleException () {
350- Opportunity opp = new Opportunity (Id = ' 00636000005loIj' , Name = ' UpdateName' );
351- Opportunity opp2 = new Opportunity (Id = ' 00636000005loIj' , Amount = 250 );
349+ private static void testRegisterDirty_ExpectReplacement () {
350+ final Opportunity insertedOpp = new Opportunity (Name = ' Original' , StageName = ' Open' , CloseDate = System .today ());
351+ insert insertedOpp ;
352+
353+ Opportunity opp = new Opportunity (Id = insertedOpp .Id , Name = ' Never' );
354+ Opportunity opp2 = new Opportunity (Id = insertedOpp .Id , Name = ' Expected' );
355+
352356 fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork (MY_SOBJECTS );
353357 uow .registerDirty (opp );
354- Boolean exceptionThrown = false ;
355- try {
356- // Second registration would undo updates of first registration
357- uow .registerDirty (opp2 );
358- } catch (fflib_SObjectUnitOfWork .UnitOfWorkException e ) {
359- System .assert (e .getMessage ().contains (opp .Id ));
360- exceptionThrown = true ;
361- }
362- System .assert (exceptionThrown );
358+ uow .registerDirty (opp2 );
359+ uow .commitWork ();
360+
361+ Opportunity updated = [select Id , Name from Opportunity where Id = :insertedOpp .Id ];
362+ System .assertEquals (' Expected' , updated .Name );
363363 }
364364
365365 /**
@@ -381,7 +381,7 @@ private with sharing class fflib_SObjectUnitOfWorkTest
381381 uow .registerDirty (amountUpdate , new List <SObjectField > { Opportunity .Amount } );
382382 uow .commitWork ();
383383
384- opp = [SELECT Name , Amount FROM Opportunity WHERE Id = : opp .Id ];
384+ opp = [select Name , Amount from Opportunity where Id = :opp .Id ];
385385 System .assertEquals (opp .Name , nameUpdate .Name );
386386 System .assertEquals (opp .Amount , amountUpdate .Amount );
387387 }
0 commit comments