Skip to content

Commit

Permalink
Added tests for getEpochTime
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-baillie-ortoo committed Feb 7, 2022
1 parent 19601ba commit 71e5297
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@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' );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>52.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@isTest
public with sharing class TimeControllerTest
{
@isTest
private static void getEpochTime_whenCalled_returnsEpochInSeconds() // NOPMD: Test method name format
{
Test.startTest();
Long got = TimeController.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' );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>52.0</apiVersion>
<status>Active</status>
</ApexClass>

0 comments on commit 71e5297

Please sign in to comment.