Advertisement
martyychang

EventStartDateBugTest

Jun 24th, 2014
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.90 KB | None | 0 0
  1. /*
  2.  * Apex test that exposes a bug where the Event Start Time "lags" when
  3.  * being processed by triggers in the <strong>before update</strong> context.
  4.  * The test relies on the presence of a simple trigger that writes the standard
  5.  * Start Date value to the custom Activity Date Proxy field.
  6.  *
  7.  * This bug was last verified to be in existence in API 30.0.
  8.  */
  9. @isTest
  10. private class EventStartDateBugTest2 {
  11.    
  12.     /*
  13.      * We're going to start by creating an event. Next, we will update
  14.      * the event two times, changing the Start Time with each edit. The
  15.      * code will prove that during edits, the Start Time for some reason will
  16.      * always show the old value instead of the new value.
  17.      */
  18.     private static testMethod void testThatEventStartDateReflectsNewValue() {
  19.  
  20.         // Define the times that we will use for the test
  21.  
  22.         DateTime firstTime  = DateTime.newInstance(10000000);
  23.         DateTime secondTime = DateTime.newInstance(20000000);
  24.         DateTime thirdTime  = DateTime.newInstance(30000000);
  25.  
  26.         System.assert(secondTime != firstTime);
  27.         System.assert(thirdTime != secondTime);
  28.         System.assert(thirdTime != firstTime);
  29.  
  30.         // Create a new event using the first start time
  31.  
  32.         Event bugTest = new Event(
  33.             StartDateTime = firstTime,
  34.             EndDateTime = firstTime.addMinutes(5));
  35.  
  36.         insert bugTest;
  37.  
  38.         // Verify that the Activity Date Proxy is identical to the first time
  39.  
  40.         Event firstBugTest = [
  41.             SELECT Id, StartDateTime, ActivityDateProxy__c
  42.             FROM Event
  43.             WHERE Id = :bugTest.Id
  44.         ];
  45.  
  46.         System.assertEquals(
  47.             firstBugTest.StartDateTime, firstBugTest.ActivityDateProxy__c,
  48.                 'Activity Date Proxy should match Start Date Time');
  49.  
  50.         System.assertEquals(
  51.             firstTime, firstBugTest.ActivityDateProxy__c,
  52.                 'Activity Date Proxy should match the first defined time');
  53.  
  54.         // After editing the event, confirm that the unexpected result is
  55.         // actually true. Please note these assertions are written so that
  56.         // the <em>wrong</em> outcome will pass the test.
  57.  
  58.         bugTest.StartDateTime = secondTime;
  59.         bugTest.EndDateTime = secondTime.addMinutes(5);
  60.  
  61.         update bugTest;
  62.  
  63.         // Verify that the Activity Date Proxy is still set to the first time,
  64.         // even though the Start Date is showing the second time
  65.  
  66.         Event secondBugTest = [
  67.             SELECT Id, StartDateTime, ActivityDateProxy__c
  68.             FROM Event
  69.             WHERE Id = :bugTest.Id
  70.         ];
  71.  
  72.         System.assertEquals(
  73.             secondTime, secondBugTest.StartDateTime,
  74.                 'Start Date Time should match the second defined time');
  75.  
  76.         System.assertEquals(
  77.             secondTime, secondBugTest.ActivityDateProxy__c,
  78.                 'Activity Date Proxy should actually match the second time!');
  79.  
  80.         // Edit the vent one more time, confirming that the unexpected result
  81.         // is still true. One final assetion is added to fail the test by
  82.         // testing for the true expected result.
  83.  
  84.         bugTest.StartDateTime = thirdTime;
  85.         bugTest.EndDateTime = thirdTime.addMinutes(5);
  86.  
  87.         update bugTest;
  88.  
  89.         // Verify that the Activity Date Proxy is still set to the second time,
  90.         // even though the Start Date is showing the third time
  91.  
  92.         Event thirdBugTest = [
  93.             SELECT Id, StartDateTime, ActivityDateProxy__c
  94.             FROM Event
  95.             WHERE Id = :bugTest.Id
  96.         ];
  97.  
  98.         System.assertEquals(
  99.             thirdTime, thirdBugTest.StartDateTime,
  100.                 'Start Date Time should match the third defined time');
  101.  
  102.         System.assertEquals(
  103.             thirdTime, thirdBugTest.ActivityDateProxy__c,
  104.                 'Activity Date Proxy should actually match the third time!');
  105.  
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement