function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MnZ321MnZ321 

Help with test class Coverage.

Following is apex class
public class OrderTrackingList{
    public OrderTrackingList(ApexPages.StandardController controller) {}
    public list<wrapgroupwise> singlegroup;
    public List<wrapgroupwise> getStartHere(){
    singlegroup= new List<wrapgroupwise>();
    List<orders__c> tempacc=[SELECT Orders__c,CreatedBy.FirstName,CreatedDate, number_of_line_items__c, CurrencyIsoCode,account__r.name,contract__r.ContractNumber,customer_order_number__c,invoices__c,my_view__c,order_acknowlegment__c,order_date__c,order_value__c, order_no__c, requested_delivery_date__c,shipments__c,Id,Name,
                                 (SELECT Id, name,calculated_estimated_delivery_date__c,order_number__c,status__c,planned_ship_date__c,material_name__c,material_no__c, quantity_ordered__c From Order_Lines__r),
                                 (SELECT Id,Name,Order_Number__c,Actual_Delivery_Date__c, estimated_delivery_date__c,Shipment_Number__r.name, Shipment_Number__r.carrrier_name__c, Shipment_Number__r.carrier_website__c,Shipment_Number__r.tracking_number__c,quantity_shipped__c  From Shipment_Lines__r)
                                 FROM orders__c where id=:ApexPages.currentPage().getParameters().get('id')];
 
     for(Integer i=0; i<tempacc.size() ; i++){
        List <order_lines__c> tempOrderLines = tempacc[i].order_lines__r;
        List <shipment_lines__c> tempShipmentLines = tempacc[i].shipment_lines__r;
        
         System.debug('temp order '+tempacc.size());
         System.debug('temp order lines'+tempOrderLines.size());
         System.debug('temp shipment lines'+tempShipmentLines.size());
         
      if(tempOrderLines.size()==0 && tempShipmentLines.size()==0){
                  singlegroup.add(new wrapgroupwise(tempacc[i],null,null)); 
        }
        else{
         
         if(tempShipmentLines.size()==0)
         {
              if(tempOrderLines[i].status__c=='Open')
               {
                   tempOrderLines[i].calculated_estimated_delivery_date__c=tempOrderLines[i].planned_ship_date__c;
               }
                                 
            singlegroup.add(new wrapgroupwise(tempacc[i],tempOrderLines,null)); 
                  
          }//if condition for tempShipmentLines size check    
         else
         {
         //Estimated Delivery Date done

           if(tempOrderLines[i].status__c=='Open')
           {
               tempOrderLines[i].calculated_estimated_delivery_date__c=tempOrderLines[i].planned_ship_date__c;
           }
           if(tempOrderLines[i].status__c=='Invoiced')
           {
               tempOrderLines[i].calculated_estimated_delivery_date__c=tempShipmentLines[i].estimated_delivery_date__c;
           }
           if(tempOrderLines[i].status__c=='Shipped but not billed')
           {
               tempOrderLines[i].calculated_estimated_delivery_date__c=tempShipmentLines[i].estimated_delivery_date__c;
           }           
     
          singlegroup.add( new wrapgroupwise(tempacc[i],tempOrderLines,tempShipmentLines)); 
         }//size check of temp shipping order  
    
        }
       }
    return singlegroup; 
   }
     public class wrapgroupwise
     {
        public List<order_lines__c> con {get;set;}
        public orders__c acc {get;set;}
        public List<shipment_lines__c> opp {get;set;}
    
         public wrapgroupwise( orders__c a , list<order_lines__c> c,list<shipment_lines__c> o)
         {
            acc=a;
            con=c;
            opp=o;
          } 
      } 
}
Following is my attempted Test Class. If and else conditions are not being covered. How to cover?
@isTest
public class OrderTrackingList_Test{ 
    static testMethod void coverCode(){
             
              Profile pf= [SELECT Id FROM Profile WHERE name= 'System Administrator' LIMIT 1];
              
              Account acc = new Account(Name='ABC Corp.');
              insert acc;
              //System.assertEquals('ABC Corp.', acc.name);
              
              orders__c tempOrder = new orders__c();
              tempOrder.name = '0001234567';
              tempOrder.account__c = acc.id;
              insert tempOrder;
      
              List <orders__c> testO = [select id, name from orders__c limit 1];
              System.assertEquals(1, testO.size());
        
         	  order_lines__c tempOL = new order_lines__c();          
              tempOL.Name = '10';
              tempOL.number_of_order_lines__c = tempOrder.id;
              tempOL.status__c='Open';
        	  tempOL.calculated_estimated_delivery_date__c=date.today();
        	  tempOL.planned_ship_date__c = date.today();
              insert tempOL;
              
 
        	   
              order_lines__c tempOL2 = new order_lines__c();
              tempOL2.Name = '10';
              tempOL2.number_of_order_lines__c = tempOrder.id;
              tempOL2.status__c='Shipped but not billed';
        	  tempOL2.calculated_estimated_delivery_date__c=date.today();
              insert tempOL2;
        
              List <order_lines__c> testOL = [select id, name, status__c, number_of_order_lines__c  from order_lines__c limit 1 ];/*where id=:ApexPages.currentPage().getParameters().get('id')*/
              System.assertEquals(1, testOL.size());

              
              shipment_lines__c tempSL = new shipment_lines__c();
              tempSL.Name = '10'; 
              tempSL.CurrencyIsoCode = 'USD'; 
        	  tempSL.estimated_delivery_date__c = date.today();
              insert tempSL;
        

        
        
        	  List <shipment_lines__c> testSL = [select name, CurrencyIsoCode  from shipment_lines__c limit 1];
              System.assertEquals(1, testSL.size());

              Test.startTest();
        	  PageReference pageRef =Page.OrderTrackingList;
        	  pageRef.getParameters().put('id', tempOrder.id);
              Test.setCurrentPage(pageRef);

              OrderTrackingList gepwO  = new OrderTrackingList(new ApexPages.StandardController(tempOrder));  
 		      gepwO.getStartHere();
        	  Test.stopTest();
    }
    static testMethod void coverCode2(){
    	Account acc1 = new Account(Name='GE. Corp.');
        insert acc1;
              
        orders__c tempOrder1 = new orders__c();
        tempOrder1.name = '0001234567';
        tempOrder1.account__c = acc1.id;
        insert tempOrder1;
        
             order_lines__c tempOL1 = new order_lines__c();          
              tempOL1.Name = '10';
              tempOL1.number_of_order_lines__c = tempOrder1.id;
              tempOL1.status__c='Invoiced';
        	  tempOL1.calculated_estimated_delivery_date__c=date.today();
        	  tempOL1.planned_ship_date__c = date.today();
              insert tempOL1;
        
        	  shipment_lines__c tempSL1 = new shipment_lines__c();
              tempSL1.Name = '10'; 
              tempSL1.CurrencyIsoCode = 'USD'; 
        	  tempSL1.estimated_delivery_date__c = date.today();
              insert tempSL1;        
        
        
        
    }
  
    }
Actually only the if-else statements are not being covered. How to cover them?

Tushar sharmaTushar sharma
To cover the if- else part you need to make different method for each if - else. and in the method you need to provide data to satisfy your condittion. in meethod you nedd to change status 
tempOrderLines[i].status__c=='Open'
from different value then you can acheive your if - else coverage