You need to sign in to do that
Don't have an account?

write test class for wrapper and else statement
Hey,
I am having issues getting the converage for the apex class (newCom). This class gives users a list of record and they can click any number of cases to attach them to the parent (Billing_Change_Form__c). I am getting 67% coverage but I am not able to cover the else statement lines.
My apex class (newCom)
My test class

The uncovered lines in the picture are where the users are click and select the cases.
Any help will be appreciated.
Thanks!
I am having issues getting the converage for the apex class (newCom). This class gives users a list of record and they can click any number of cases to attach them to the parent (Billing_Change_Form__c). I am getting 67% coverage but I am not able to cover the else statement lines.
My apex class (newCom)
// Controller for Billing Form Button on Account public with sharing class newCom { //Declare variables public account acc{get;set;} public Billing_Change_Form__c comBill {get;set;} id acID = System.currentPagereference().getParameters().get('id'); public list<conCase> caseList{get;set;} public boolean bool{get;set;} public set<id> caseIds{get;set;} ApexPages.StandardController controller; public string result{get;set;} //Contructor public newCom (ApexPages.StandardController con){ comBill = new Billing_change_form__c(); id acID = System.currentPagereference().getParameters().get('id'); comBill.RecordTypeId = '0124A000001lBu9QAE'; comBill.Account__c = acId; controller = con; caseList = new list<conCase>(); bool = false; caseIds = new Set<id>(); } //Event on clicking the checkbox public void inIt(){ List<Contingency__c> selectedCase = new list<Contingency__c>(); for(conCase conObj : caseList){ if(conObj.check != False) { system.debug('conObj.con'+ conObj.con); selectedCase.add(conObj.con); caseIds.add(conObj.con.id); bool = true; } If(conObj.check != true) {caseIds.remove(conObj.con.id); } } } //Displaying the case findings records public List<conCase> getShow(){ caseList = new list <conCase> (); for(Contingency__c coObj : [Select id, name,billing_type__c, report_description__c, discovery_amount__c, billing_begins_date__c, contingency__c, VENDOR_INVOICE__r.Account_del__r.Id from Contingency__c where (VENDOR_INVOICE__r.Account_del__r.Id = :acID) AND (contingency__c like 'IN BILLING') ORDER BY NAME]) {caseList.add(new conCase(coObj, Bool));} return caseList; } //Event on saving public PageReference comInsert(){ // newBill.RecordTypeId = '0124A000001lBu9QAE'; // Inserting the new record list<Contingency__c> noSelectedCase = [select id, name, bill_form__c from Contingency__c where id = :caseIds ]; if(noSelectedCase.size()<1){ combill.adderror('Please select a case for this form'); ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, ' Please select a case for this form' )); return null; } else{ comBill.name = 'Nada'; comBill.account__c = acID; insert comBill; result = comBill.Id; //Inserting Case Findings list<Contingency__c> updateSelectedCase = new list<Contingency__c>(); for(Contingency__c co:[select id, name, bill_form__c from Contingency__c where id = :caseIds ]) {co.bill_form__c =result ; updateSelectedCase.add(co);} update updateSelectedCase; //Redirecting Page to new record created PageReference rePage = new PageReference('/'+result); rePage.setRedirect(true); rePage.getParameters().put('id',controller.getId()); return repage;} } //Event on hitting the cancel button public PageReference noBill(){ comBill.Reason_for_Removal__c = 'Our Error'; comBill.Total_Adjustment_Amount__c = 1; comBill.Name = 'Nada'; PageReference pageRef = new PageReference('/'+acId); pageRef.setRedirect(true); return pageRef; } //Wrapper class for the selected records public class conCase{ public contingency__c con{get;set;} public boolean check{get;set;} public conCase(contingency__c c, boolean boo){ con = c; check = boo; } } }
My test class
public static testMethod void btnTestCom(){ Account accTest = new Account(); accTest.Name = 'Test Account'; insert accTest; Account accTest2 = new Account(); accTest2.Name = 'Test Account2'; insert accTest2; Account_number__c venTest = new Account_Number__c(); venTest.Name = 'Test Ven'; venTest.Account_del__c = accTest.id; insert venTest; Account_number__c venTest2 = new Account_Number__c(); venTest2.Name = 'Test Ven2'; venTest2.Account_del__c = accTest2.id; insert venTest2; Billing_Change_form__c testBill2 = new Billing_Change_Form__c(); testBill2.Name = 'Test name2'; testBill2.Reason_for_Removal__c = 'Term Completed'; testbill2.Reason_what_why__c = 'nada'; testbill2.Total_Adjustment_Amount__c = 123; insert testBill2; Billing_Change_form__c testBill = new Billing_Change_Form__c(); testBill.Name = 'Test name'; testBill.Reason_for_Removal__c = 'Term Completed'; testbill.Reason_what_why__c = 'nada'; testbill.Total_Adjustment_Amount__c = 123; insert testBill; Contingency__c caseTest = new Contingency__c(); caseTest.Name = 'test Case'; caseTest.Contingency__c = 'IN BILLING'; caseTest.vendor_invoice__c = venTest.id; insert caseTest; Contingency__c caseTest2 = new Contingency__c(); caseTest2.Name = 'test Case2'; caseTest2.Contingency__c = 'IN BILLING'; caseTest2.Bill_form__c = testBill.Id ; caseTest2.vendor_invoice__c = venTest2.id; insert caseTest2; Set<id> caseIds = new Set<id>(); caseIds.add(caseTest.id); caseIds.add(caseTest2.id); Test.startTest(); PageReference pageRef = Page.accBill; // Add your VF page Name here pageRef.getParameters().put('id', String.valueOf(testBill.Id)); Test.setCurrentPage(pageRef); ApexPages.StandardController sc = new ApexPages.StandardController(testBill); newCom testAccPlan = new newCom(sc); newCre.conCase wrap1 = new newCre.conCase(caseTest2, false); wrap1.check = true; wrap1.con = caseTest2; list<newCre.conCase> caseList = new list<newCre.conCase>(); caseList.add(wrap); caseList.add(wrap1); testAccPlan.inIt(); testAccPlan.getShow(); testAccPlan.comInsert(); testAccPlan.noBill(); test.stopTest(); }
Any help will be appreciated.
Thanks!
All Answers
I already tried that but it still covering those lines.