I'm writing a test for a schedulable class and so far it's working fine but I can't get the return statement to be covered by the test class. I'm missing something here and can't see it.
The final returns on getMonthName (return Name) and getQuarter(Return Quarter) methods are not covered by the test class.
Here the Schedulable Class:
global class MRD_LATAM_LeaseCorrection implements Schedulable {
global void execute(SchedulableContext SC)
{
ListofLeases();
}
global static void ListOfLeases (){
List<Margin_Report_Data__c> Corrections = new List<Margin_Report_Data__c>();
//Loop for year
Integer m=date.today().month();
for (Integer y=date.today().year(); y <= 2026 ; y++ ){
//Loop for month
while (m <=12){
Margin_Report_Data__c mrd = new Margin_Report_Data__c();
mrd.Account__c='001f000001Fd5sIAAR';
mrd.Customer__c = 'LATAM AIRLINES GROUP S.A.';
mrd.Transaction_Date__c = date.newInstance(y, m, 1);
mrd.Transaction_Year__c = string.valueOf(y);
mrd.Transaction_Month__c = getMonthName(m);
mrd.Transaction_Quarter__c = getQuarter(m);
mrd.Program_Revenue__c = 'No';
mrd.Sale_Category__c='Leases';
mrd.Region__c='LA';
mrd.Total_Sales__c = 194800;
mrd.Total_Gross_Profit__c = 194800;
mrd.Post_Status__c = 'Posted';
mrd.Transaction_Description__c = 'Sale Income Adjustment for LATAM Lease';
Corrections.add(mrd);
m++;
}
m=1;
}
for (Margin_Report_Data__c mr : Corrections){
}
insert Corrections;
}
//Converting month number to month name
global static String getMonthName (Integer Month){
String Name;
Switch on Month{
when 1 {
Name='January';
return Name;
}
when 2 {
Name='February';
return Name;
}
when 3 {
Name='March';
return Name;
}
when 4 {
Name='April';
return Name;
}
when 5 {
Name='May';
return Name;
}
when 6 {
Name='June';
return Name;
}
when 7 {
Name='July';
return Name;
}
when 8 {
Name='August';
return Name;
}
when 9 {
Name='September';
return Name;
}
when 10 {
Name='October';
return Name;
}
when 11 {
Name='November';
return Name;
}
when 12 {
Name='December';
return Name;
}
}
return Name; //<-- This is not covered
}
//Converting month number to year quarter
global static String getQuarter (Integer Month){
String Quarter;
Switch on Month{
when 1 {
Quarter = 'Q1';
return Quarter;
}
when 2 {
Quarter = 'Q1';
return Quarter;
}
when 3 {
Quarter = 'Q1';
return Quarter;
}
when 4 {
Quarter = 'Q2';
return Quarter;
}
when 5 {
Quarter = 'Q2';
return Quarter;
}
when 6 {
Quarter = 'Q2';
return Quarter;
}
when 7 {
Quarter = 'Q3';
return Quarter;
}
when 8 {
Quarter = 'Q3';
return Quarter;
}
when 9 {
Quarter = 'Q3';
return Quarter;
}
when 10 {
Quarter = 'Q4';
return Quarter;
}
when 11 {
Quarter = 'Q4';
return Quarter;
}
when 12 {
Quarter = 'Q4';
return Quarter;
}
}
return Quarter; //<-- This is not covered
}
}
Here's the test class:
@IsTest
public class MRD_LATAM_LeaseCorrection_Test {
@IsTest static void TestDeleteData(){
//Setup Margin Report
Margin_Report_Data__c MarginReport = new Margin_Report_Data__c (Transaction_Month__c='January', Transaction_Year__c='2018', Document_Number__c='10', Sales_Order__c='12345');
Test.startTest();
MRD_LATAM_LeaseCorrection mrdc = new MRD_LATAM_LeaseCorrection();
String sch = '0 59 12 * * ?';
system.schedule('Test MR Lease Correction', sch, mrdc);
mrdc.execute(null);
Test.stoptest();
List <Margin_Report_Data__c> resultmr = [SELECT id FROM Margin_Report_Data__c WHERE Customer__c = 'LATAM AIRLINES GROUP S.A.' AND Sale_Category__c = 'Leases'];
System.debug('MRD With Leases?:'+ resultmr.size());
System.assertEquals(true, resultmr.size()>0);
}
}