Test class to control Singleton Stub
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
@IsTest | |
public with sharing class SingletonTest { | |
@IsTest | |
public static void testLeapYear() { | |
//not stubbed out, so this will take the normal path w/o the switch | |
SingletonController.printDateTime(); | |
} | |
@IsTest | |
public static void testNonLeapYear() { | |
//IS stubbed out, so this WILL take the alternate path | |
DateTime newNow = DateTime.newInstance(2019, 9, 8); | |
DateTimeProvider.instance = new DateTimeStub(newNow); | |
SingletonController.printDateTime(); | |
//in the wild, return data and make assertions here | |
} | |
private with sharing class DateTimeStub extends DateTimeProvider { | |
public DateTime now; | |
public DateTimeStub(DateTime now) { | |
this.now = now; | |
} | |
public override DateTime now() { | |
return now; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment