I need to get code coverage on UpgradeRate, PlusCount2, PremiumCount2 and PrestigeCount2, but what I have is not working. How do I get code coverage on these? In my custom controller, I have the following wrapper class:
public class employee{
public Decimal PlusCount{get;set;}
public Decimal PlusCount2 {get{if(PlusCount == 0){return 0;}else return PlusCount.setScale(0);}}
public Decimal PremiumCount{get;set;}
public Decimal PremiumCount2 {get{if(PremiumCount == 0){return 0;}else return PremiumCount.setScale(0);}}
public Decimal PrestigeCount{get;set;}
public Decimal PrestigeCount2 {get{if(PrestigeCount == 0){return 0;}else return PrestigeCount.setScale(0);}}
public Decimal UpgradeRate{
get{
if(PlusCount == 0 &&(PrestigeCount != 0 || PremiumCount != 0)){
return 100;
} else if(PlusCount == 0 && PrestigeCount == 0 && PremiumCount == 0){
return 0;
} else return ((PremiumCount + PrestigeCount) / (PremiumCount + PrestigeCount + PlusCount)).setScale(3) * 100;
}
}
public employee(AggregateResult i){
PlusCount = (Decimal)i.get('plus_count');
PremiumCount = (Decimal)i.get('premium_count');
PrestigeCount = (Decimal)i.get('prestige_count');
}
}
I am able to get code coverage for PlusCount, PremiumCount, and PrestigeCount, with the following test class:
List<FranchiseMetrics.employee> employees = new List<FranchiseMetrics.employee>();
AggregateResult[] employeeInspections = new AggregateResult[]{};
employeeInspections = [SELECT Count(id) Total,Sum(Number_of_Home_Inspections__c) HomeInspections, AVG(Invoice_Sub_Total__c) AJS, Sum(Invoice_Sub_Total__c) TotalDollars,Sum(Added_Service_Cost__c) ServiceCost,
Sum(Home_Inspection_dollars__c) HomeDollars, Inspector__r.FirstName Name,
Sum(Plus_Sales__c) plus_dollars, Sum(Premium_Sales__c) premium_dollars, Sum(Prestige_Sales__c) prestige_dollars,
Sum(of_Plus_Sales__c) plus_count, Sum(of_Premium_Sales__c) premium_count, Sum(of_Prestige_Sales__c) prestige_count,
Sum(Added_Services__c) addedservices, Sum(Standalones__c) standalones
FROM Inspection__c
WHERE Test_Inspection__c = false AND Status__c = 'Completed' AND Franchise__c =: acct.id
GROUP BY Inspector__r.FirstName
ORDER BY Inspector__r.FirstName];
for(AggregateResult e: employeeInspections){
Decimal UpgradeRate;
Decimal PlusCount = (Decimal)e.get('plus_count');
Decimal PremiumCount = (Decimal)e.get('premium_count');
Decimal PrestigeCount = (Decimal)e.get('prestige_count');
if(PlusCount == 0 &&(PrestigeCount != 0 || PremiumCount != 0)){
UpgradeRate = 100;
} else if(PlusCount == 0 && PrestigeCount == 0 && PremiumCount == 0){
UpgradeRate = 0;
} else UpgradeRate = ((PremiumCount + PrestigeCount) / (PremiumCount + PrestigeCount + PlusCount)).setScale(3) * 100;
employees.add(new FranchiseMetrics.employee(e));
Decimal PlusCount2;
if(PlusCount == 0){PlusCount2 = 0;}else PlusCount2 = PlusCount.setScale(0);
}
public Decimal PlusCount2 {get{if(PlusCount == 0){return 0;}else return PlusCount.setScale(0);}}
is inefficient as compared to justpublic Decimal PlusCount2 { get { return PlusCount.setScale(0); } }
.