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.
Improved split between DateLiterals and DateTimeUtils
Added tests
- Loading branch information
1 parent
e8d1113
commit 08124af
Showing
11 changed files
with
159 additions
and
40 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
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
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
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
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
77 changes: 62 additions & 15 deletions
77
framework/default/ortoo-core/default/classes/utils/tests/DateTimeUtilsTest.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 |
---|---|---|
@@ -1,18 +1,65 @@ | ||
@isTest | ||
public with sharing class DateTimeUtilsTest | ||
{ | ||
@isTest | ||
private static void getEpochTime_whenCalled_returnsEpochInSeconds() // NOPMD: Test method name format | ||
{ | ||
Test.startTest(); | ||
Long got = DateTimeUtils.getEpochTime(); | ||
Test.stopTest(); | ||
|
||
Integer e9 = Integer.valueOf( got / 1000000000 ); // if you divide the epoch seconds by 10^9, you should get 1 if the date is later than 9th September 2001 | ||
Integer e10 = Integer.valueOf( ( got / 1000000000 ) / 10 ); // if you divide the epoch seconds by 10^10, you should get < 1 if the date is earlier than 20th November 2286 | ||
// need to do it in two steps becayse 10^10 is not a valid integer | ||
|
||
System.assert( e9 > 0, 'getEpochTime, when called, will return the epoch time in seconds - being greater than 10^9' ); | ||
System.assertEquals( 0, e10, 'getEpochTime, when called, will return the epoch time in seconds - being less than 10^10' ); | ||
} | ||
} | ||
@isTest | ||
private static void convertToEpochTime_whenGivenADateTime_convertsItToEpochInSeconds() // NOPMD: Test method name format | ||
{ | ||
DateTime timeToConvert = DateTime.newInstanceGmt( 2020, 5, 1, 13, 45, 0 ); | ||
Long expected = 1588340700; | ||
|
||
Test.startTest(); | ||
Long got = DateTimeUtils.convertToEpochTime( timeToConvert ); | ||
Test.stopTest(); | ||
|
||
System.assertEquals( expected, got, 'convertToEpochTime, when given a date time, will convert it to epoch in seconds' ); | ||
} | ||
|
||
@isTest | ||
private static void convertToEpochTime_whenPassedANullTimeToConvert_throwsAnException() // NOPMD: Test method name format | ||
{ | ||
Test.startTest(); | ||
String exceptionMessage; | ||
try | ||
{ | ||
DateTimeUtils.convertToEpochTime( null ); | ||
} | ||
catch ( Contract.RequiresException e ) | ||
{ | ||
exceptionMessage = e.getMessage(); | ||
} | ||
Test.stopTest(); | ||
|
||
ortoo_Asserts.assertContains( 'convertToEpochTime called with a null timeToConvert', exceptionMessage, 'convertToEpochTime, when passed a null timeToConvert, will throw an exception' ); | ||
} | ||
|
||
@isTest | ||
private static void convertToDateTime_whenGivenAEpochInSeconds_convertsItToDateTime() // NOPMD: Test method name format | ||
{ | ||
Long epochInSeconds = 1588340700; | ||
DateTime expected = DateTime.newInstanceGmt( 2020, 5, 1, 13, 45, 0 ); | ||
|
||
Test.startTest(); | ||
DateTime got = DateTimeUtils.convertToDateTime( epochInSeconds ); | ||
Test.stopTest(); | ||
|
||
System.assertEquals( expected, got, 'convertToDateTime, when given an epoch time in seconds, will convert it to DateTime' ); | ||
} | ||
|
||
@isTest | ||
private static void convertToDateTime_whenPassedANullEpochInSeconds_throwsAnException() // NOPMD: Test method name format | ||
{ | ||
Test.startTest(); | ||
String exceptionMessage; | ||
try | ||
{ | ||
DateTimeUtils.convertToDateTime( null ); | ||
} | ||
catch ( Contract.RequiresException e ) | ||
{ | ||
exceptionMessage = e.getMessage(); | ||
} | ||
Test.stopTest(); | ||
|
||
ortoo_Asserts.assertContains( 'convertToDateTime called with a null epochInSeconds', exceptionMessage, 'convertToDateTime, when passed a null epochInSeconds, will throw an exception' ); | ||
} | ||
} |
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