I am new for test classes even I written test class it's covered 34% but I need to increase code coverage. Please can any one help me out how to increase my code coverage, please find below my apex class,test class and error message.
public class Rfleet_PaymentConditions {
public Boolean bool {get;set;}
public Boolean boolsave {get;set;}
public Boolean showSave{get;set;}
public Boolean showSubmit{get;set;}
public Boolean showback{get;set;}
public string id;
public Account acc{get;set;}
public Boolean refreshPage {get; set;}
public Account getAccount() {
return acc;
}
public Rfleet_PaymentConditions(ApexPages.StandardController controller){
bool = true;
showSave = true;
id=ApexPages.currentPage().getParameters().get('id');
acc=[SELECT Rfleet_UpperDate_Period1__c,Rfleet_UpperMonth_Period1__c,Rfleet_LowerDate_Period1__c,Rfleet_LowerMonth_Period1__c,Rfleet_DueDate_Period1__c,Rfleet_DueMonth_Period1__c,Rfleet_UpperDate_Period2__c,Rfleet_UpperMonth_Period2__c,Rfleet_LowerDate_Period2__c,Rfleet_LowerMonth_Period2__c,Rfleet_DueDate_Period2__c,Rfleet_DueMonth_Period2__c,
Rfleet_Depreciation_UpperDate_Period1__c,Rfleet_Depreciation_UpperMonth_Period1__c,Rfleet_Depreciation_LowerDate_Period1__c,Rfleet_Depreciation_LowerMonth_Period1__c,Rfleet_Depreciation_DueDate_Period1__c,Rfleet_Depreciation_DueMonth_Period1__c,Rfleet_Depreciation_UpperDate_Period2__c,Rfleet_Depreciation_UpperMonth_Period2__c,Rfleet_Depreciation_LowerDate_Period2__c,
Rfleet_Depreciation_LowerMonth_Period2__c,Rfleet_Depreciation_DueDate_Period2__c,Rfleet_Depreciation_DueMonth_Period2__c,Event_Triggering_Billing__c,Rfleet_Billing_Type__c,Rfleet_Billing_Delay__c FROM Account where id=:id];
}
public void ResetPayment(){
acc.Rfleet_UpperDate_Period1__c='';
acc.Rfleet_UpperMonth_Period1__c='';
acc.Rfleet_LowerDate_Period1__c='';
acc.Rfleet_LowerMonth_Period1__c='';
acc.Rfleet_DueDate_Period1__c='';
acc.Rfleet_DueMonth_Period1__c='';
acc.Rfleet_UpperDate_Period2__c='';
acc.Rfleet_UpperMonth_Period2__c='';
acc.Rfleet_LowerDate_Period2__c='';
acc.Rfleet_LowerMonth_Period2__c='';
acc.Rfleet_DueDate_Period2__c='';
acc.Rfleet_DueMonth_Period2__c='';
acc.Event_Triggering_Billing__c='';
acc.Rfleet_Billing_Type__c='';
acc.Rfleet_Billing_Delay__c=0;
}
public void ResetDepreciationPayment(){
acc.Rfleet_Depreciation_UpperDate_Period1__c='';
acc.Rfleet_Depreciation_UpperMonth_Period1__c='';
acc.Rfleet_Depreciation_LowerDate_Period1__c='';
acc.Rfleet_Depreciation_LowerMonth_Period1__c='';
acc.Rfleet_Depreciation_DueDate_Period1__c='';
acc.Rfleet_Depreciation_DueMonth_Period1__c='';
acc.Rfleet_Depreciation_UpperDate_Period2__c='';
acc.Rfleet_Depreciation_UpperMonth_Period2__c='';
acc.Rfleet_Depreciation_LowerDate_Period2__c='';
acc.Rfleet_Depreciation_LowerMonth_Period2__c='';
acc.Rfleet_Depreciation_DueDate_Period2__c='';
acc.Rfleet_Depreciation_DueMonth_Period2__c='';
}
public void save(){
bool =false;
boolsave=false;
showSave=false;
showSubmit=true;
showback=true;
}
public PageReference back(){
refreshPage=true;
return null;
}
public PageReference Submit() {
if((acc.Rfleet_UpperDate_Period1__c==Null ||acc.Rfleet_UpperMonth_Period1__c==Null||acc.Rfleet_LowerDate_Period1__c==Null||acc.Rfleet_LowerMonth_Period1__c==Null||acc.Rfleet_DueDate_Period1__c==Null||acc.Rfleet_DueMonth_Period1__c==Null||acc.Rfleet_UpperDate_Period2__c==Null||acc.Rfleet_UpperMonth_Period2__c==Null||acc.Rfleet_LowerDate_Period2__c==Null||acc.Rfleet_LowerMonth_Period2__c==Null||acc.Rfleet_DueDate_Period2__c==Null||acc.Rfleet_DueMonth_Period2__c==Null)|| (acc.Rfleet_Depreciation_UpperDate_Period1__c==null ||acc.Rfleet_Depreciation_UpperMonth_Period1__c==null ||acc.Rfleet_Depreciation_LowerDate_Period1__c==null ||acc.Rfleet_Depreciation_LowerMonth_Period1__c==null ||acc.Rfleet_Depreciation_DueDate_Period1__c==null ||acc.Rfleet_Depreciation_DueMonth_Period1__c==null ||acc.Rfleet_Depreciation_UpperDate_Period2__c==null ||acc.Rfleet_Depreciation_UpperMonth_Period2__c==null ||acc.Rfleet_Depreciation_LowerDate_Period2__c==null ||acc.Rfleet_Depreciation_LowerMonth_Period2__c==null ||acc.Rfleet_Depreciation_DueDate_Period2__c==null ||acc.Rfleet_Depreciation_DueMonth_Period2__c==null)){
boolsave=true;
Apexpages.addmessage(new Apexpages.Message(ApexPages.Severity.Warning,'please must fill all Terms of Payment fields!'));
}else{
update acc;
Apexpages.addmessage(new Apexpages.Message(ApexPages.Severity.INFO,'Record saved Successfully!'));
refreshPage=true;
}
return null;
}
//period1 LowerDate validation
public PageReference Period1LowerDateValidation(){
if(acc.Rfleet_LowerDate_Period1__c!=Null && acc.Rfleet_LowerMonth_Period1__c != Null && acc.Rfleet_UpperMonth_Period1__c!=null && acc.Rfleet_UpperDate_Period1__c !=null ){
boolsave=false;
if((Integer.valueof(acc.Rfleet_LowerDate_Period1__c)> Integer.valueof(acc.Rfleet_UpperDate_Period1__c)) && (acc.Rfleet_LowerMonth_Period1__c==acc.Rfleet_UpperMonth_Period1__c)){
boolsave=true;
ApexPages.Message msg = new Apexpages.Message(ApexPages.Severity.Warning,'Please select the past Date of lowerdate in Period1!!');
ApexPages.addmessage(msg);
}else if((Integer.valueof(acc.Rfleet_LowerDate_Period1__c)== Integer.valueof(acc.Rfleet_UpperDate_Period1__c)) && (acc.Rfleet_LowerMonth_Period1__c==acc.Rfleet_UpperMonth_Period1__c)){
boolsave=true;
ApexPages.Message msg = new Apexpages.Message(ApexPages.Severity.Warning,'Should not same lowerdate/UpperDate in Period1!!');
ApexPages.addmessage(msg);
}else if((acc.Rfleet_UpperMonth_Period1__c=='M') &&(acc.Rfleet_LowerMonth_Period1__c=='M + 1'||acc.Rfleet_LowerMonth_Period1__c=='M + 2'|| acc.Rfleet_LowerMonth_Period1__c=='M + 3')){
boolsave=true;
ApexPages.Message msg = new Apexpages.Message(ApexPages.Severity.Warning,'Please select the past month LowerDate in Period1!!');
ApexPages.addmessage(msg);
}else if((acc.Rfleet_UpperMonth_Period1__c=='M + 1') &&(acc.Rfleet_LowerMonth_Period1__c=='M + 2'|| acc.Rfleet_LowerMonth_Period1__c=='M + 3')){
boolsave=true;
ApexPages.Message msg = new Apexpages.Message(ApexPages.Severity.Warning,'Please select the past month LowerDate in Period1!!');
ApexPages.addmessage(msg);
}else if(acc.Rfleet_UpperMonth_Period1__c=='M + 2' && acc.Rfleet_LowerMonth_Period1__c=='M + 3'){
boolsave=true;
ApexPages.Message msg = new Apexpages.Message(ApexPages.Severity.Warning,'Please select the past month LowerDate in Period1!!');
ApexPages.addmessage(msg);
}else if((acc.Rfleet_UpperMonth_Period1__c=='M - 1') &&(acc.Rfleet_LowerMonth_Period1__c=='M'|| acc.Rfleet_LowerMonth_Period1__c=='M + 1'|| acc.Rfleet_LowerMonth_Period1__c=='M + 2'|| acc.Rfleet_LowerMonth_Period1__c=='M + 3')){
boolsave=true;
ApexPages.Message msg = new Apexpages.Message(ApexPages.Severity.Warning,'Please select the past month LowerDate in Period1!!');
ApexPages.addmessage(msg);
}else if((acc.Rfleet_UpperMonth_Period1__c=='M - 2') &&(acc.Rfleet_LowerMonth_Period1__c=='M - 1'|| acc.Rfleet_LowerMonth_Period1__c=='M'|| acc.Rfleet_LowerMonth_Period1__c=='M + 1'|| acc.Rfleet_LowerMonth_Period1__c=='M + 2'|| acc.Rfleet_LowerMonth_Period1__c=='M + 3')){
boolsave=true;
ApexPages.Message msg = new Apexpages.Message(ApexPages.Severity.Warning,'Please select the past month LowerDate in Period1!!');
ApexPages.addmessage(msg);
}else if((acc.Rfleet_UpperMonth_Period1__c=='M - 3') &&(acc.Rfleet_LowerMonth_Period1__c=='M - 1'|| acc.Rfleet_LowerMonth_Period1__c=='M - 2'|| acc.Rfleet_LowerMonth_Period1__c=='M'|| acc.Rfleet_LowerMonth_Period1__c=='M + 1'|| acc.Rfleet_LowerMonth_Period1__c=='M + 2'|| acc.Rfleet_LowerMonth_Period1__c=='M + 3')){
boolsave=true;
ApexPages.Message msg = new Apexpages.Message(ApexPages.Severity.Warning,'Please select the past month LowerDate in Period1!!');
ApexPages.addmessage(msg);
}
}
return null;
}
Test class:
@isTest
public class Rfleet_PaymentConditions_Test {
static testMethod void testpayment(){
Account acct = new Account(Name='kathir',Montant__c=5,Rfleet_UpperDate_Period1__c='21',Rfleet_UpperMonth_Period1__c='M + 1',Rfleet_LowerDate_Period1__c='21',
Rfleet_LowerMonth_Period1__c='M - 1',Rfleet_DueDate_Period1__c='21',Rfleet_DueMonth_Period1__c='M + 2',Rfleet_UpperDate_Period2__c='21',
Rfleet_UpperMonth_Period2__c='M + 3',Rfleet_LowerDate_Period2__c='21',Rfleet_LowerMonth_Period2__c='M - 2',Rfleet_DueDate_Period2__c='21',
Rfleet_DueMonth_Period2__c='M + 3',Rfleet_Depreciation_UpperDate_Period1__c='21',Rfleet_Depreciation_UpperMonth_Period1__c='M + 1',
Rfleet_Depreciation_LowerDate_Period1__c='21',Rfleet_Depreciation_LowerMonth_Period1__c='M - 3',
Rfleet_Depreciation_DueDate_Period1__c='21',Rfleet_Depreciation_DueMonth_Period1__c='M + 2',Rfleet_Depreciation_UpperDate_Period2__c='21',
Rfleet_Depreciation_UpperMonth_Period2__c='M + 1',Rfleet_Depreciation_LowerDate_Period2__c='21',
Rfleet_Depreciation_LowerMonth_Period2__c='M - 3',Rfleet_Depreciation_DueDate_Period2__c='21',Rfleet_Depreciation_DueMonth_Period2__c='M + 3');
insert acct;
acct.Name='joshua';
update acct;
Account paytest = [Select id,Name,Rfleet_UpperMonth_Period1__c from account LIMIT 100];
pagereference vfpage = page.RFLEET_PaymetCondition;
system.Test.setCurrentPage(vfpage);
ApexPages.currentPage().getParameters().put('id', paytest.id);
apexpages.StandardController sc = new apexpages.StandardController(paytest);
Rfleet_PaymentConditions pay = new Rfleet_PaymentConditions(sc);
pay.save();
pay.back();
pay.getAccount();
pay.boolsave=true;
pay.Submit();
pay.Period1LowerDateValidation();
pay.Period1UpperDateValidation();
pay.Period1DueDateValidation();
pay.Period2LowerDateValidation();
pay.Period2UpperdateValidation();
pay.Period2DuedateValidation();
pay.DepreciationPeriod1LowerDateValidation();
pay.DepreciationPeriod1UpperDateValidation();
pay.DepreciationPeriod1DueDateValidation();
pay.DepreciationPeriod2UpperDateValidation();
pay.DepreciationPeriod2LowerDateValidation();
pay.DepreciationPeriod2DueDateValidation();
pay.ResetPayment();
pay.ResetDepreciationPayment();
}
}