If anyone has a better idea for a subject - feel free to update.
So I'm setting a private variable in my constructor. I also have some logic in place to set that variable. I want to test both positive and negative aspects of my logic in the constructor. Typically I have a public boolean that I use in test to "Force" a set of logic. However, I'm not sure how to use this since in the test I instantiate the constructor and then can set the variable. the Constructor logic has already fired.
Code:
private final Case c;
private final ID vOwnerID;
public boolean ErrorTest = false;
public Case_ContactUs_Ext(ApexPages.StandardController con) {
this.c = (Case)con.getRecord();
list<Group> Queues = [SELECT DeveloperName,Email,Id,Name,OwnerId,RelatedId,Type
FROM Group WHERE Type = 'Queue' AND DeveloperName = 'CustomerSupportQueue'];
if(Queues != null && Queues.size()>0 && ErrorTest == false){
vOwnerID = Queues[0].id;
}else{
list<User> lUser = [SELECT Id,Name,ProfileId,Profile.Name FROM User where Profile.Name = 'System Administrator'];
vOwnerID = lUser[0].id;
}
}
So my test:
static testMethod void testCase_ContactUS_Ext_Error() {
Case c = new Case();
insert c;
ApexPages.StandardController sc = new ApexPages.standardController(c);
Case_ContactUs_Ext ext = new Case_ContactUs_Ext(sc);
ext.ErrorTest = true;
PageReference pageRef = Page.ContactUs;
Test.setCurrentPage(pageRef);
ext.SaveCase();
}
Is there a better way to do this?

