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

Strucked in test class code coverage
HI Folks
I got strucked in code coverage, Now i have 63% coverage, Please do help.
@RestResource(urlMapping='/api/IVR/*') global class IVRRestAPI { @HttpPost global static List<IVR__c> CreateIVR(List<createIVR> icretIVR) { try{ Set<String> loanId = new Set<String>(); List<Loan__c> loanlst = new List<Loan__c>(); Map<String,String> mpidtoname = new Map<String,String>(); List<IVR__c> IVRlst = new List<IVR__c>(); for(createIVR icret:icretIVR) { if(icret.LoanID != null) { loanId.add(icret.LoanID); } } System.debug('loanId '+loanId); if(loanId.size() > 0) { loanlst = [SELECT Id,Name FROM Loan__c WHERE Name IN:loanId]; } System.debug('loanlst '+loanlst); if(loanlst.size() > 0) { for(Loan__c iloan:loanlst) { mpidtoname.put(iloan.Name,iloan.Id); } } System.debug('mpidtoname '+mpidtoname); for(createIVR icret:icretIVR) { IVR__c IVR = new IVR__c(); if(mpidtoname.containskey(icret.LoanID)) { IVR.Loan_Id__c = mpidtoname.get(icret.LoanID); } IVR.Name = icret.IVRId; IVR.Merchant_Name__c = icret.MerchantName; IVR.IVR_Number__c = icret.IVRNumber; IVR.Disbursed_Amount__c = Decimal.valueOf(icret.DisbursedAmount); IVR.Disbursed_Date_Time__c = date.ValueOf(icret.DisbursedDateTime); IVRlst.add(IVR); } if(IVRlst.size() > 0) { insert IVRlst; return IVRlst; } return null; }catch(exception e){System.debug(e.getmessage() + e.getlinenumber());return null;} } global class createIVR { public String IVRId; public String LoanID; public String DisbursedAmount; public String MerchantName; Public String DisbursedDateTime; Public String IVRNumber; public createIVR(String IVRId,String LoanID,String DisbursedAmount,String MerchantName,String DisbursedDateTime,String IVRNumber){} } }
Test Class
@istest public class IVRRestAPITest{ static testMethod void IVRRestAPITest(){ IVRRestAPI reqst=new IVRRestAPI(); String JsonMsg=JSON.serialize(reqst); RestRequest req = new RestRequest(); req.addHeader('Content-Type', 'application/json'); req.requestURI = '/services/apexrest/api/IVR/CreateIVR'; req.httpMethod = 'POST'; req.requestBody = Blob.valueof(JsonMsg); RestResponse res = new RestResponse(); RestContext.request = req; RestContext.response= res; Test.startTest(); List<IVRRestAPI.createIVR> icretIVRList = new List<IVRRestAPI.createIVR>(); icretIVRList.add(new IVRRestAPI.CreateIVR('Name','LoanID','DisbursedAmount','MerchantName','DisbursedDateTime','IVRNumber') ); IVRRestAPI.CreateIVR(icretIVRList); Test.stopTest(); } }
Below lines are not covered in test class.
18 loanId.add(icret.LoanID);
24 loanlst = [SELECT Id,Name FROM Loan__c WHERE Name IN:loanId];
29 for(Loan__c iloan:loanlst)
30 {
31 mpidtoname.put(iloan.Name,iloan.Id);
41 IVR.Loan_Id__c = mpidtoname.get(icret.LoanID);
49 IVR.Disbursed_Date_Time__c = date.ValueOf(icret.DisbursedDateTime);
50 IVRlst.add(IVR);
51 }
52 if(IVRlst.size() > 0)
53 {
54 insert IVRlst;
55 return IVRlst;
56 }
57 return null;
Please do help to get code coverage.
Thanks in Advance.
please mark this as solved
Thanks, good luck !