Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Apex test that exposes a bug where the Event Start Time "lags" when
- * being processed by triggers in the <strong>before update</strong> context.
- * The test relies on the presence of a simple trigger that writes the standard
- * Start Date value to the custom Activity Date Proxy field.
- *
- * This bug was last verified to be in existence in API 30.0.
- */
- @isTest
- private class EventStartDateBugTest2 {
- /*
- * We're going to start by creating an event. Next, we will update
- * the event two times, changing the Start Time with each edit. The
- * code will prove that during edits, the Start Time for some reason will
- * always show the old value instead of the new value.
- */
- private static testMethod void testThatEventStartDateReflectsNewValue() {
- // Define the times that we will use for the test
- DateTime firstTime = DateTime.newInstance(10000000);
- DateTime secondTime = DateTime.newInstance(20000000);
- DateTime thirdTime = DateTime.newInstance(30000000);
- System.assert(secondTime != firstTime);
- System.assert(thirdTime != secondTime);
- System.assert(thirdTime != firstTime);
- // Create a new event using the first start time
- Event bugTest = new Event(
- StartDateTime = firstTime,
- EndDateTime = firstTime.addMinutes(5));
- insert bugTest;
- // Verify that the Activity Date Proxy is identical to the first time
- Event firstBugTest = [
- SELECT Id, StartDateTime, ActivityDateProxy__c
- FROM Event
- WHERE Id = :bugTest.Id
- ];
- System.assertEquals(
- firstBugTest.StartDateTime, firstBugTest.ActivityDateProxy__c,
- 'Activity Date Proxy should match Start Date Time');
- System.assertEquals(
- firstTime, firstBugTest.ActivityDateProxy__c,
- 'Activity Date Proxy should match the first defined time');
- // After editing the event, confirm that the unexpected result is
- // actually true. Please note these assertions are written so that
- // the <em>wrong</em> outcome will pass the test.
- bugTest.StartDateTime = secondTime;
- bugTest.EndDateTime = secondTime.addMinutes(5);
- update bugTest;
- // Verify that the Activity Date Proxy is still set to the first time,
- // even though the Start Date is showing the second time
- Event secondBugTest = [
- SELECT Id, StartDateTime, ActivityDateProxy__c
- FROM Event
- WHERE Id = :bugTest.Id
- ];
- System.assertEquals(
- secondTime, secondBugTest.StartDateTime,
- 'Start Date Time should match the second defined time');
- System.assertEquals(
- secondTime, secondBugTest.ActivityDateProxy__c,
- 'Activity Date Proxy should actually match the second time!');
- // Edit the vent one more time, confirming that the unexpected result
- // is still true. One final assetion is added to fail the test by
- // testing for the true expected result.
- bugTest.StartDateTime = thirdTime;
- bugTest.EndDateTime = thirdTime.addMinutes(5);
- update bugTest;
- // Verify that the Activity Date Proxy is still set to the second time,
- // even though the Start Date is showing the third time
- Event thirdBugTest = [
- SELECT Id, StartDateTime, ActivityDateProxy__c
- FROM Event
- WHERE Id = :bugTest.Id
- ];
- System.assertEquals(
- thirdTime, thirdBugTest.StartDateTime,
- 'Start Date Time should match the third defined time');
- System.assertEquals(
- thirdTime, thirdBugTest.ActivityDateProxy__c,
- 'Activity Date Proxy should actually match the third time!');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement