Skip to content

Commit

Permalink
Added some edge case tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-baillie-ortoo committed Feb 24, 2022
1 parent 9850046 commit c0794ac
Showing 1 changed file with 61 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
@isTest
private without sharing class ortoo_DateLiteralsTest
{
// TODO: start of and end of this, on the day that is already start or end

@isTest
private static void today_whenReferenced_returnsTodaysDate() // NOPMD: Test method name format
{
Date got = ortoo_DateLiterals.today;
System.assertEquals( Date.today(), got, 'today, when referenced, is set to today' );
System.assertEquals( Date.today(), got, 'today is set to today' );
}

@isTest
Expand All @@ -20,7 +18,7 @@ private without sharing class ortoo_DateLiteralsTest
Date got = ortoo_DateLiterals.yesterday;
Test.stopTest();

System.assertEquals( Date.newInstance( 2024, 02, 29 ), got, 'yesterday, when referenced, is set to yesterday, based on the configured "today"' );
System.assertEquals( Date.newInstance( 2024, 02, 29 ), got, 'yesterday is set to yesterday, based on the configured "today"' );
}

@isTest
Expand All @@ -32,7 +30,7 @@ private without sharing class ortoo_DateLiteralsTest
Date got = ortoo_DateLiterals.tomorrow;
Test.stopTest();

System.assertEquals( Date.newInstance( 2024, 03, 01 ), got, 'tomorrow, when referenced, is set to tomorrow, based on the configured "today"' );
System.assertEquals( Date.newInstance( 2024, 03, 01 ), got, 'tomorrow is set to tomorrow, based on the configured "today"' );
}

@isTest
Expand All @@ -47,7 +45,20 @@ private without sharing class ortoo_DateLiteralsTest
Date expectedEarliest = Date.newInstance( 2024, 02, 25 );
Date expectedLatest = Date.newInstance( 2024, 02, 26 );

ortoo_Asserts.assertBetweenInclusive( expectedEarliest, expectedLatest, got, 'startOfThisWeek, when referenced, is set to the start of this week, based on the configured "today" and the current user locale' );
ortoo_Asserts.assertBetweenInclusive( expectedEarliest, expectedLatest, got, 'startOfThisWeek is set to the start of this week, based on the configured "today" and the current user locale' );
}

@isTest
private static void startOfThisWeek_whenItIsTheStartOfTheWeek_returnsToday() // NOPMD: Test method name format
{
Date startOfThisWeek = ortoo_DateLiterals.startOfThisWeek;
ortoo_DateLiterals.today = startOfThisWeek;

Test.startTest();
Date got = ortoo_DateLiterals.startOfThisWeek;
Test.stopTest();

System.assertEquals( startOfThisWeek, got, 'startOfThisWeek, when today is the start of the week, will return today' );
}

@isTest
Expand All @@ -62,7 +73,20 @@ private without sharing class ortoo_DateLiteralsTest
Date expectedEarliest = Date.newInstance( 2024, 03, 02 );
Date expectedLatest = Date.newInstance( 2024, 03, 03 );

ortoo_Asserts.assertBetweenInclusive( expectedEarliest, expectedLatest, got, 'endOfThisWeek, when referenced, is set to the end of this week, based on the configured "today" and the current user locale' );
ortoo_Asserts.assertBetweenInclusive( expectedEarliest, expectedLatest, got, 'endOfThisWeek is set to the end of this week, based on the configured "today" and the current user locale' );
}

@isTest
private static void endOfThisWeek_whenItIsTheStartOfTheWeek_returnsToday() // NOPMD: Test method name format
{
Date endOfThisWeek = ortoo_DateLiterals.endOfThisWeek;
ortoo_DateLiterals.today = endOfThisWeek;

Test.startTest();
Date got = ortoo_DateLiterals.endOfThisWeek;
Test.stopTest();

System.assertEquals( endOfThisWeek, got, 'endOfThisWeek, when today is the end of the week, will return today' );
}

@isTest
Expand All @@ -77,7 +101,7 @@ private without sharing class ortoo_DateLiteralsTest
Date expectedEarliest = Date.newInstance( 2024, 02, 18 );
Date expectedLatest = Date.newInstance( 2024, 02, 19 );

ortoo_Asserts.assertBetweenInclusive( expectedEarliest, expectedLatest, got, 'startOfLastWeek, when referenced, is set to the start of last week, based on the configured "today" and the current user locale' );
ortoo_Asserts.assertBetweenInclusive( expectedEarliest, expectedLatest, got, 'startOfLastWeek is set to the start of last week, based on the configured "today" and the current user locale' );
}

@isTest
Expand All @@ -92,7 +116,7 @@ private without sharing class ortoo_DateLiteralsTest
Date expectedEarliest = Date.newInstance( 2024, 02, 24 );
Date expectedLatest = Date.newInstance( 2024, 02, 25 );

ortoo_Asserts.assertBetweenInclusive( expectedEarliest, expectedLatest, got, 'endOfLastWeek, when referenced, is set to the end of last week, based on the configured "today" and the current user locale' );
ortoo_Asserts.assertBetweenInclusive( expectedEarliest, expectedLatest, got, 'endOfLastWeek is set to the end of last week, based on the configured "today" and the current user locale' );
}

@isTest
Expand Down Expand Up @@ -120,7 +144,7 @@ private without sharing class ortoo_DateLiteralsTest
Date expectedEarliest = Date.newInstance( 2024, 03, 03 );
Date expectedLatest = Date.newInstance( 2024, 03, 04 );

ortoo_Asserts.assertBetweenInclusive( expectedEarliest, expectedLatest, got, 'startOfNextWeek, when referenced, is set to the start of next week, based on the configured "today" and the current user locale' );
ortoo_Asserts.assertBetweenInclusive( expectedEarliest, expectedLatest, got, 'startOfNextWeek is set to the start of next week, based on the configured "today" and the current user locale' );
}

@isTest
Expand All @@ -135,7 +159,7 @@ private without sharing class ortoo_DateLiteralsTest
Date expectedEarliest = Date.newInstance( 2024, 03, 09 );
Date expectedLatest = Date.newInstance( 2024, 03, 10 );

ortoo_Asserts.assertBetweenInclusive( expectedEarliest, expectedLatest, got, 'endOfNextWeek, when referenced, is set to the end of next week, based on the configured "today" and the current user locale' );
ortoo_Asserts.assertBetweenInclusive( expectedEarliest, expectedLatest, got, 'endOfNextWeek is set to the end of next week, based on the configured "today" and the current user locale' );
}

@isTest
Expand All @@ -162,6 +186,19 @@ private without sharing class ortoo_DateLiteralsTest
System.assertEquals( Date.newInstance( 2024, 02, 01 ), got, 'startOfThisMonth, is set to the start of this month, based on the configured today' );
}

@isTest
private static void startOfThisMonth_whenItIsTheStartOfTheMonth_returnsToday() // NOPMD: Test method name format
{
Date startOfThisMonth = ortoo_DateLiterals.startOfThisMonth;
ortoo_DateLiterals.today = startOfThisMonth;

Test.startTest();
Date got = ortoo_DateLiterals.startOfThisMonth;
Test.stopTest();

System.assertEquals( startOfThisMonth, got, 'startOfThisMonth, when today is the start of the month, will return today' );
}

@isTest
private static void endOfThisMonth_whenReferenced_returnsEndOfThisMonthBasedOnTheConfiguredToday() // NOPMD: Test method name format
{
Expand All @@ -174,6 +211,19 @@ private without sharing class ortoo_DateLiteralsTest
System.assertEquals( Date.newInstance( 2024, 02, 29 ), got, 'endOfThisMonth, is set to the end of this month' );
}

@isTest
private static void endOfThisMonth_whenItIsTheStartOfTheMonth_returnsToday() // NOPMD: Test method name format
{
Date endOfThisMonth = ortoo_DateLiterals.endOfThisMonth;
ortoo_DateLiterals.today = endOfThisMonth;

Test.startTest();
Date got = ortoo_DateLiterals.endOfThisMonth;
Test.stopTest();

System.assertEquals( endOfThisMonth, got, 'endOfThisMonth, when today is the end of the month, will return today' );
}

@isTest
private static void startOfLastMonth_whenReferenced_returnsStartOfLastMonthBasedOnTheConfiguredToday() // NOPMD: Test method name format
{
Expand Down

0 comments on commit c0794ac

Please sign in to comment.