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
vishwa attikerivishwa attikeri 

How to cover inside the IF conditions code in test class

Please any one help me on this issue,

how to cover the code inside the if condition in test class

public class Pocinsert
{

public List<Plan_of_Care__c> mplan {get; set;}  
 public Pocinsert(){
 mplan = new List<Plan_of_Care__c>();
 makeAvailabilityWindow();
}
  
public String Employee='';

public String getEmployee()
{
return Employee;
}
public void setEmployee(String Employee)
{
this.Employee=Employee;
}

public List<SelectOption> getEmployees()
{
List<SelectOption> option=new List<SelectOption>();
option.add(new SelectOption('', '- None -')); 
for(Employee__c e:[select id,name,lastname__c from Employee__c order by name ASC])
{

option.add(new SelectOption(e.id,e.lastname__c+'-'+e.name));
}
return option;
}

String Client ='';
public String getclient()
{
return client;
}
public void setclient(String Client)
{
this.client=client;
}

public List<SelectOption> getClients()
{
List<SelectOption> option= new List<SelectOption>();
option.add(new SelectOption('', '- None -')); 
for(Client__c c:[select id,name,lastname__c from Client__c where Employee__c =: Employee order by name ASC])
{
option.add(new selectoption(c.id,c.lastname__c+'-'+c.name));
}
return option;
}
  
public void makeAvailabilityWindow()
{
 numberDays = date.daysInMonth(Integer.valueof(selectedYears), Integer.valueof(selectedMonths));
 for(Integer i=1; i<=numberDays; i++){
 day_L.add(String.valueof(i));
 }
   
   for(Integer j=1; j<=numberDays; j++){
    mplan.add(new Plan_of_Care__c());
                 }
     }
                
  public PageReference savem(){ 
  Integer count = mplan.size();
  Integer i = 0; 
  if(Client!=null && Employee!=null)
   {          
      do {
             Integer d = i+1;
            if(mplan[i].Tub_Bath_Shower__c <> 'XX' && mplan[i].Tub_Bath_Shower__c <> null)
             {               
                  mplan[i].Tub_Bath_Shower__c.addError('Input Field value must be XX');
                  PageReference opptyPage = new PageReference('/apex/InsertPOC');
                  return opptyPage; 
              }

          if(mplan[i].Tub_Showertransfer_Position__c <> 'XX' && mplan[i].Tub_Showertransfer_Position__c <> null)
            {
                mplan[i].Tub_Showertransfer_Position__c.addError('Input Field value must be XX');
                PageReference opptyPage = new PageReference('/apex/InsertPOC');
                return opptyPage;
             }      
          if(mplan[i].Bed_Bath__c <> 'XX' && mplan[i].Bed_Bath__c <> null)
             {               
                  mplan[i].Bed_Bath__c.addError('Input Field value must be XX');
                  PageReference opptyPage = new PageReference('/apex/InsertPOC');
                  return opptyPage; 
              }

           
        mplan[i].Client__c=client;
        mplan[i].Employee__c=Employee;      
        mplan[i].date__c=date.newInstance(Integer.valueof(selectedYears),Integer.valueof(selectedMonths),d);
              
               
                i++;
                d=0;
                } while (i < count);
           }              
           upsert mplan;                          
                                
            PageReference home = new PageReference('/apex/InsertPOC');        
            home.setRedirect(true);        
            return home;                    
            }
			}

 

 

Sridhar BonagiriSridhar Bonagiri

Hi,

 

Make sure that what ever you are checking in the IF condition for a varibale , the value should be available for that variable, both in positive and negative scenarios.

vishwa attikerivishwa attikeri

Hi, 

i am new for test class, can u tel how to pass the variable

 

 

Thank u

vishwa attikerivishwa attikeri

Hi,

 

Please any one help me to solve this problem..

 

Starz26Starz26

In your test class call

 

setClient('YOUR STRING');

setEmployee('YOUR STRING');

 

This will set the value of Client and Employee and make it not = NULL.

 

Now if these are set elsewhere in your class, you have to set up the test class to create the needed records or ensure whatever is needed for the class to return those values is present in the database.