You need to sign in to do that
Don't have an account?
Harjeet Singh
test class coverage problem
Hi All,
I am working on a test class for a class which was created by me nut unfortunately i am not able to increase the code coverage beyond 67%.
P.F.A the controller and test class.
Following lines of code is not getting covered after so much permutations and combinations.
All these lines are called behind "Proceed" button.
This forum helped me earlier many times and this time again i am very hopeful and can expect that i would be able to make it beyond 75%.Many thanks in advance..
I am working on a test class for a class which was created by me nut unfortunately i am not able to increase the code coverage beyond 67%.
P.F.A the controller and test class.
public with sharing class TfB_PB_AccountActionsWrapper{ public List<wrapSubscription> SubscriptionSetList{get;set;} public integer size{get;set;} public Date currentDateValue { get; set; } public String selectedActions{get;set;} public csord__Subscription__c vSub{get;set;} public List<csord__Subscription__c> vLstSub{get;set;} public Map<Id, List<csord__Subscription__c>> AccIdSubListMap { get; set; } public Opportunity oppList; public Map<Id, List<csord__Service__c>> SubIdServListMap { get; set; } Map<Id, csord__Subscription__c> subMap = new Map<Id, csord__Subscription__c>(); public boolean AccountBool{get;set;} public boolean fals{get;set;} public Date SysDate{get;set;} public Account vAccount{get;set;} public Account vSourceAccount{get;set;} public String contextItem{get;set;} public integer noOfRecords{get;set;} public set<csord__Subscription__c > selectedSubscription; public List<csord__Subscription__c > selectedSubscriptionList; public set<id> subids; public Id OpptyId; public string accountId; public String baseQuery; //Constructor for the class public TfB_PB_AccountActionsWrapper( ){ AccIdSubListMap=new Map<Id, List<csord__Subscription__c>>(); SubIdServListMap= new Map<Id, List<csord__Service__c>>(); vSub= new csord__Subscription__c(); selectedActions='Takeover'; if(selectedActions=='Takeover'){ AccountBool=true; } fals= false; this.subids = new set<id>(); selectedSubscriptionList = new List<csord__Subscription__c >(); this.selectedSubscription = new set<csord__Subscription__c>(); SubscriptionSetList = new List<wrapSubscription>(); accountId=ApexPages.currentPage().getParameters().get('id'); } //Following property will pick values from the custom setting public List<selectOption> ActionValues { get { List<selectOption> options = new List<selectOption>(); for (TfB_PB_ChangeType__c cType : TfB_PB_ChangeType__c.getAll().values()) options.add(new SelectOption(cType.Name,cType.Name)); return options; } set; } //This function implements the pagination logic public ApexPages.StandardSetController SubSetController{ get{ if(SubSetController == null){ size =20; SubSetController = new ApexPages.StandardSetController([SELECT Name, csord__Status__c,csord__Account__c,MACD_in_progress__c,Billing_Account_Number__c,(select Id,Billing_Account_Number__c from csord__Services__r) FROM csord__Subscription__c where csord__Account__c=:accountId order by Billing_Account_Number__c desc nulls Last]); system.debug('Return Records $$$$$$$$'+SubSetController); this.SubSetController.setpageNumber(1); this.SubSetController.setPageSize(size); noOfRecords = SubSetController.getResultSize(); } return SubSetController; }set; } //Below logic is used for enable/disable of Target Account field based on Action field value public void getDisplayAccount( ){ if(selectedActions!='Takeover'){ AccountBool=false; } else{ AccountBool=true; } } //Following function implements wrapper logic public List<wrapSubscription> getCurrentList( ){ updateSelectedSubscriptions(); SubscriptionSetList = new List<wrapSubscription>(); for (csord__Subscription__c vSubscription : (List<csord__Subscription__c >)SubSetController.getRecords( )){ system.debug('vSubscription @@@@@@@@@ '+vSubscription); if(selectedSubscription.contains(vSubscription)) SubscriptionSetList.add(new wrapSubscription(vSubscription,'true')); else SubscriptionSetList.add(new wrapSubscription(vSubscription)); system.debug('SubscriptionSetList########'+SubscriptionSetList); } fals=false; return SubscriptionSetList; } //This method update the selected Subscriptions List in the wrapper Class public void updateSelectedSubscriptions( ){ for(wrapSubscription cs: SubscriptionSetList){ if(cs.selected){ selectedSubscription.add(cs.vSub); selectedSubscriptionList.addAll(selectedSubscription); system.debug('++++++++'+selectedSubscriptionList.size()); } else{ if(selectedSubscription.contains(cs.vSub)) selectedSubscription.remove(cs.vSub); } } } //This method adding the selected subscriptions to the list public void doSelectItem( ){ if(contextItem!=null) this.subids.add(this.contextItem); } //This method remove the deselected subscriptions to the list public void doDeselectItem( ){ this.subids.remove(this.contextItem); } //This method count the selected subscriptions public Integer getSelectedCount( ){ // subids.clear(); for(csord__Subscription__c acc: selectedSubscription){ subids.add(acc.id); } return this.subids.size(); } //Below method implements the Next button logic for pagination public void doNext( ){ if(this.SubSetController.getHasNext()) this.SubSetController.next(); } //Below method for the Previous button logic for pagination public void doPrevious( ){ if(this.SubSetController.getHasPrevious()) this.SubSetController.previous(); } public Boolean getHasPrevious( ){ return this.SubSetController.getHasPrevious(); } //Below method implements the Next button logic for pagination public Boolean getHasNext( ){ return this.SubSetController.getHasNext(); } //Following method returns the current page number in pagination logic public Integer getPageNumber( ){ return this.SubSetController.getPageNumber(); } //Following function implements the total pages number public Integer getTotalPages( ){ Decimal totalSize = this.SubSetController.getResultSize(); Decimal pageSize = this.SubSetController.getPageSize(); Decimal pages = totalSize/pageSize; return (Integer)pages.round(System.RoundingMode.CEILING); } //Below method has logic for Cancel button used in pagination public PageReference cancel( ){ return new PageReference('/'+accountid); } //Following function will perform the validations behind the Continue button& restrict an user to proceed to next page if any of the validation fails.Also invokes the method provided by CS Team. public pageReference Proceed( ){ SysDate = System.today(); accountId=ApexPages.currentPage().getParameters().get('id'); if(vSub.csord__Account__c!= null){ vAccount=[Select Name,TINA_Parent_Cust_Number__c,TfB_PB_CreditCheckExpiryDate__c,TfB_PB_CreditCheckResponse__c from Account where Id=:vSub.csord__Account__c]; } vSourceAccount = [Select Name,TINA_Parent_Cust_Number__c,TfB_PB_CreditCheckExpiryDate__c,TfB_PB_CreditCheckResponse__c from Account where Id=:accountId]; if(selectedActions =='Takeover'){ if(vSub.csord__Account__c==null){ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Please select The Target Account'); ApexPages.addMessage(myMsg); return null; } if(vSub.csord__Account__c==accountId){ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'The target account is the same as the current account, it has to be different.'); ApexPages.addMessage(myMsg); return null; } if(vAccount.TfB_PB_CreditCheckExpiryDate__c== null){ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'The credit check for this account is missing an expiry date, you need to do another credit check before entering the Takeover order.'); ApexPages.addMessage(myMsg); return null; } if(vAccount.TfB_PB_CreditCheckExpiryDate__c <= SysDate){ system.debug('Negative Else1----'); ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'The Credit Check results have reached the expiry date. Please perform the Credit Check from the account before performing Order'); ApexPages.addMessage(myMsg); return null; } if(vAccount.TfB_PB_CreditCheckResponse__c == 'Positive' || vAccount.TfB_PB_CreditCheckResponse__c == 'ERROR'){ system.debug('========='+subids); if(subids.size()>0){ try { system.debug('@@@@@@@@@@ :'+selectedSubscriptionList.size()); system.debug('###########:'+vAccount.Id); system.debug('***********:'+selectedActions); system.debug('%%%%%%%%%%%:'+currentDateValue); OpptyId = TB_PB_CloneOpportunity.createClonedOpportunity(selectedSubscriptionList,vAccount.Id,selectedActions,currentDateValue); system.debug('Opportunity Id is :'+OpptyId); PageReference pageOpportunity = new PageReference('/'+OpptyId); system.debug('pageOpportunity is :'+pageOpportunity ); pageOpportunity.setRedirect(false); return pageOpportunity; } catch(Exception e) { ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'There was a technical problem encountered while carrying out this order. To retry click on Continue button again, if you still get this message please take a screen print and log a ticket in Remedy force'); ApexPages.addMessage(myMsg); } return null; } else{ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'You need to select atleast one subscription'); ApexPages.addMessage(myMsg); return null; } } if(vAccount.TfB_PB_CreditCheckResponse__c == 'Negative-1'){ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'You cannot proceed with Order Intake since the customer has a negative credit check -1'); ApexPages.addMessage(myMsg); return null; } if(vAccount.TfB_PB_CreditCheckResponse__c == 'Negative-2'){ system.debug('Negative----'); ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'You cannot proceed with Order Intake since the customer has a negative credit check -2'); ApexPages.addMessage(myMsg); return null; } if(vAccount.TfB_PB_CreditCheckResponse__c == null || vAccount.TfB_PB_CreditCheckResponse__c!='POSITIVE' ||vAccount.TfB_PB_CreditCheckResponse__c!='NEGATIVE-1'||vAccount.TfB_PB_CreditCheckResponse__c!='NEGATIVE-2'||vAccount.TfB_PB_CreditCheckResponse__c!='ERROR' ){ system.debug('Negative Else----'); ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'The account does not have a positive credit check, you need to get an approval to continue with the order'); ApexPages.addMessage(myMsg); return null; } return null; } else if(selectedActions =='Move'){ if(vSourceAccount.TfB_PB_CreditCheckExpiryDate__c== null){ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'The credit check for this account is missing an expiry date, you need to do another credit check before entering the Takeover order.'); ApexPages.addMessage(myMsg); return null; } if(vSourceAccount.TfB_PB_CreditCheckExpiryDate__c <= SysDate){ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'The Credit Check results have reached the expiry date. Please perform the Credit Check from the account before performing Order'); ApexPages.addMessage(myMsg); return null; } if(vSourceAccount.TfB_PB_CreditCheckResponse__c == 'Positive'|| vSourceAccount.TfB_PB_CreditCheckResponse__c == 'ERROR'){ system.debug('========='+subids); if(subids.size()>0){ try { system.debug('@@@@@@@@@@ :'+selectedSubscriptionList.size()); system.debug('###########:'+null); system.debug('***********:'+selectedActions); system.debug('%%%%%%%%%%%:'+currentDateValue); OpptyId = TB_PB_CloneOpportunity.createClonedOpportunity(selectedSubscriptionList,null,selectedActions,currentDateValue); system.debug('Opportunity Id is :'+OpptyId); PageReference pageOpportunity = new PageReference('/'+OpptyId); system.debug('pageOpportunity is :'+pageOpportunity ); pageOpportunity.setRedirect(false); return pageOpportunity; } catch(Exception e) { ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'There was a technical problem encountered while carrying out this order. To retry click on Continue button again, if you still get this message please take a screen print and log a ticket in Remedy force'); ApexPages.addMessage(myMsg); } return null; } else{ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'You need to select atleast one subscription'); ApexPages.addMessage(myMsg); return null; } } if(vSourceAccount.TfB_PB_CreditCheckResponse__c == 'Negative-1'){ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'You cannot proceed with Order Intake since the customer has a negative credit check -1'); ApexPages.addMessage(myMsg); return null; } if(vSourceAccount.TfB_PB_CreditCheckResponse__c == 'Negative-2'){ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'You cannot proceed with Order Intake since the customer has a negative credit check -2'); ApexPages.addMessage(myMsg); return null; } if(vSourceAccount.TfB_PB_CreditCheckResponse__c == null || vSourceAccount.TfB_PB_CreditCheckResponse__c!='POSITIVE' ||vSourceAccount.TfB_PB_CreditCheckResponse__c!='NEGATIVE-1'||vSourceAccount.TfB_PB_CreditCheckResponse__c!='NEGATIVE-2'||vSourceAccount.TfB_PB_CreditCheckResponse__c!='ERROR' ){ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'The account does not have a positive credit check, you need to get an approval to continue with the order'); ApexPages.addMessage(myMsg); return null; } return null; } else{ system.debug('========='+subids); if(subids.size()>0){ try { system.debug('@@@@@@@@@@ :'+selectedSubscriptionList.size()); system.debug('###########:'+null); system.debug('***********:'+selectedActions); system.debug('%%%%%%%%%%%:'+currentDateValue); OpptyId = TB_PB_CloneOpportunity.createClonedOpportunity(selectedSubscriptionList,null,selectedActions,currentDateValue); system.debug('Opportunity Id is :'+OpptyId); PageReference pageOpportunity = new PageReference('/'+OpptyId); system.debug('pageOpportunity is :'+pageOpportunity ); pageOpportunity.setRedirect(false); return pageOpportunity; } catch(Exception e) { ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'There was a technical problem encountered while carrying out this order. To retry click on Continue button again, if you still get this message please take a screen print and log a ticket in Remedy force'); ApexPages.addMessage(myMsg); } return null; } else{ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'You need to select atleast one subscription'); ApexPages.addMessage(myMsg); return null; } } } //Wrapper class logic public class wrapSubscription{ public csord__Subscription__c vSub {get; set;} public Boolean selected {get; set;} public wrapSubscription( ){ vSub = new csord__Subscription__c(); selected = false; } public wrapSubscription(csord__Subscription__c a){ vSub = a; selected = false; } public wrapSubscription(csord__Subscription__c c,string s){ vSub=c; selected=true; } } }
Following lines of code is not getting covered after so much permutations and combinations.
All these lines are called behind "Proceed" button.
This forum helped me earlier many times and this time again i am very hopeful and can expect that i would be able to make it beyond 75%.Many thanks in advance..
Hope you have covered wrapper class if not cover like this
TfB_PB_AccountActionsWrapper.wrapSubscription wrapClsIns = new TfB_PB_AccountActionsWrapper.wrapSubscription();
TfB_PB_AccountActionsWrapper.wrapSubscription wrapClsIns = new TfB_PB_AccountActionsWrapper.wrapSubscription(csord__Subscription__c:instance);
TfB_PB_AccountActionsWrapper.wrapSubscription wrapClsIns = new TfB_PB_AccountActionsWrapper.wrapSubscription(csord__Subscription__c instance, 'test');
Thanks
Praveen Murugesan.
If you see my code then below mentioned lines are not getting covered:
Line 217-237
Line 281-301
Line 329-347.
These are try catch block..If these lines get covered then my test class coverage will go beyond 75%.
P.F.A my test class also.
Many thanks in advance.