Struggling with how best to test my controller extension - My extension onload sets a picklist value based on the month number. My issue is I can only test current month e.g. Nov. If I explicitly set it to Dec, the extension still only tests Nov. I want to test all the months. Not sure how to setup / structure the test to cover all months. Any help appreciated.
public class CommissionClaimControllerExtension {
public CommissionClaimControllerExtension(ApexPages.StandardController controller){
Commission_Claim__c plClaim = (Commission_Claim__c) controller.getRecord();
List<Opportunity> opp = [select Type_of_campaign__c,CC_Total_No_of_Leads_Published__c from Opportunity where Id =: plClaim.CC_Opportunity__c limit 1];
// On Page Load Set Defaults
if (opp.size() > 0){
plClaim.CC_Campaign_Type__c = opp[0].Type_of_campaign__c;
plClaim.CC_Total_Claimed__c = opp[0].CC_Total_No_of_Leads_Published__c;
}
date dtDate = date.today();
integer intMonth = dtDate.month();
System.debug('DEBUG/CA: month number is ' + intMonth);
if (intMonth == 1){
plClaim.CC_Month__c = 'Jan';
} else if (intMonth == 2){
plClaim.CC_Month__c = 'Feb';
} else if (intMonth == 3){
plClaim.CC_Month__c = 'Mar';
} else if (intMonth == 4){
plClaim.CC_Month__c = 'Apr';
} else if (intMonth == 5){
plClaim.CC_Month__c = 'May';
} else if (intMonth == 6){
plClaim.CC_Month__c = 'Jun';
} else if (intMonth == 7){
plClaim.CC_Month__c = 'Jul';
} else if (intMonth == 8){
plClaim.CC_Month__c = 'Aug';
} else if (intMonth == 9){
plClaim.CC_Month__c = 'Sep';
} else if (intMonth == 10){
plClaim.CC_Month__c = 'Oct';
} else if (intMonth == 11){
plClaim.CC_Month__c = 'Nov';
} else {
plClaim.CC_Month__c = 'Dec';
}
}
}
Here is my test class so far
public class CommissionClaimTests {
// Inst
static PageReference ccForm;
static PageReference ccEditForm;
static CommissionClaimControllerExtension ext;
static testMethod void testMyControllerExtension_Nov() {
ccForm = Page.CommissionClaim;
test.setCurrentPage(ccForm);
exclude_profiles__c setting = TestObjects.createCustomSetting();
Account accts = TestObjects.createTestAccounts();
Opportunity opps = TestObjects.createTestOpps(accts.Id);
Commission_Claim__c claim = new Commission_Claim__c();
ApexPages.Standardcontroller con = new ApexPages.Standardcontroller(claim);
ext = new CommissionClaimControllerExtension ( con );
test.startTest();
claim.CC_no_of_Leads_or_DD_Published__c = 1;
claim.CC_Month__c = 'Nov';
system.assert(con != null);
con.Save();
test.stopTest();
}
}
Thanks
