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

Unable to achieve sufficient test code coverage
Hi all i wrote a class and now i am working on test class for the same.
I am not able to increase the code coverage beyond 60%.
I am attaching my test class written so far and the piece of code from main class which is not getting covered.
and below is the method from my controller whhich is not getting covered after giving it so much try.
My current code coverage is 50% only and i am not able to increase it further after giving it so much try.Please help me out here to achieve sufficient code coverage.
Many thanks in advance.
I am not able to increase the code coverage beyond 60%.
I am attaching my test class written so far and the piece of code from main class which is not getting covered.
@isTest(seeAlldata=true) public class TfB_PB_TestAccountActionsWrapper { public static testMethod void myUnitTest() { PageReference pg = Page.TfB_PB_AccountActionsVf; Test.setCurrentPage(pg); Account SourceAcc = new Account(Name='Test1',C_fe_Customer_Number__c='6548681',TfB_PB_CreditCheckResponse__c='Positive',TfB_PB_CreditCheckExpiryDate__c=system.today()+1); insert SourceAcc; csord__Order_Request__c vOrderReq = new csord__Order_Request__c(); vOrderReq.Name='Test Order'; vOrderReq.csord__Module_Name__c='TestModule'; vOrderReq.csord__Module_Version__c='TestVersion'; vOrderReq.TfB_PB_Account__c=SourceAcc.Id; insert vOrderReq; csord__Subscription__c objCS = new csord__Subscription__c (csord__Account__c = SourceAcc.Id,csord__Order_Request__c=vOrderReq.Id,csord__Identification__c='abc',Name= 'Test1'); insert objCS; /*List<selectOption> options = new List<selectOption>(); options.add('Takeover'); options.add('Move');*/ TfB_PB_AccountActionsWrapper objActWap = new TfB_PB_AccountActionsWrapper(); ApexPages.currentPage().getParameters().put('id',SourceAcc.Id); objActWap.selectedActions='Move'; objActWap.Proceed(); objActWap.getDisplayAccount(); //objActWap.ActionValues=; objActWap.getCurrentList(); objActWap.updateSelectedSubscriptions(); objActWap.doSelectItem(); objActWap.doDeselectItem(); objActWap.getSelectedCount(); objActWap.doNext(); objActWap.doPrevious(); objActWap.getHasPrevious(); objActWap.getHasNext(); objActWap.cancel(); objActWap.getTotalPages(); objActWap.getPageNumber(); TfB_PB_AccountActionsWrapper.wrapSubscription AccWrapper = new TfB_PB_AccountActionsWrapper.wrapSubscription(); TfB_PB_AccountActionsWrapper.wrapSubscription AccWrapper1 = new TfB_PB_AccountActionsWrapper.wrapSubscription(objCS); TfB_PB_AccountActionsWrapper.wrapSubscription AccWrapper2 = new TfB_PB_AccountActionsWrapper.wrapSubscription(objCS,'True'); } public static testMethod void myUnitTest1() { PageReference pg = Page.TfB_PB_AccountActionsVf; Test.setCurrentPage(pg); Account SourceAcc = new Account(Name='Test1',C_fe_Customer_Number__c='6590681',TfB_PB_CreditCheckResponse__c='Negative-1',TfB_PB_CreditCheckExpiryDate__c=system.today()-1); insert SourceAcc; csord__Order_Request__c vOrderReq = new csord__Order_Request__c(); vOrderReq.Name='Test Order'; vOrderReq.csord__Module_Name__c='TestModule'; vOrderReq.csord__Module_Version__c='TestVersion'; vOrderReq.TfB_PB_Account__c=SourceAcc.Id; insert vOrderReq; csord__Subscription__c objCS = new csord__Subscription__c (csord__Account__c = SourceAcc.Id,csord__Order_Request__c=vOrderReq.Id,csord__Identification__c='abc',Name= 'Test1'); insert objCS; TfB_PB_AccountActionsWrapper objActWap = new TfB_PB_AccountActionsWrapper(); ApexPages.currentPage().getParameters().put('id',SourceAcc.Id); objActWap.selectedActions='Move'; objActWap.Proceed(); TfB_PB_AccountActionsWrapper.wrapSubscription AccWrapper = new TfB_PB_AccountActionsWrapper.wrapSubscription(); TfB_PB_AccountActionsWrapper.wrapSubscription AccWrapper1 = new TfB_PB_AccountActionsWrapper.wrapSubscription(objCS); TfB_PB_AccountActionsWrapper.wrapSubscription AccWrapper2 = new TfB_PB_AccountActionsWrapper.wrapSubscription(objCS,'True'); } public static testMethod void myUnitTest2() { PageReference pg = Page.TfB_PB_AccountActionsVf; Test.setCurrentPage(pg); Account SourceAcc = new Account(Name='Test1',C_fe_Customer_Number__c='738745936',TfB_PB_CreditCheckResponse__c='Negative-1'); insert SourceAcc; csord__Order_Request__c vOrderReq = new csord__Order_Request__c(); vOrderReq.Name='Test Order'; vOrderReq.csord__Module_Name__c='TestModule'; vOrderReq.csord__Module_Version__c='TestVersion'; vOrderReq.TfB_PB_Account__c=SourceAcc.Id; insert vOrderReq; csord__Subscription__c objCS = new csord__Subscription__c (csord__Account__c = SourceAcc.Id,csord__Order_Request__c=vOrderReq.Id,csord__Identification__c='abc',Name= 'Test1'); insert objCS; TfB_PB_AccountActionsWrapper objActWap = new TfB_PB_AccountActionsWrapper(); ApexPages.currentPage().getParameters().put('id',SourceAcc.Id); objActWap.selectedActions='Takeover'; objActWap.Proceed(); TfB_PB_AccountActionsWrapper.wrapSubscription AccWrapper = new TfB_PB_AccountActionsWrapper.wrapSubscription(); TfB_PB_AccountActionsWrapper.wrapSubscription AccWrapper1 = new TfB_PB_AccountActionsWrapper.wrapSubscription(objCS); TfB_PB_AccountActionsWrapper.wrapSubscription AccWrapper2 = new TfB_PB_AccountActionsWrapper.wrapSubscription(objCS,'True'); } public static testMethod void myUnitTest3() { PageReference pg = Page.TfB_PB_AccountActionsVf; Test.setCurrentPage(pg); Account SourceAcc = new Account(Name='Test1',C_fe_Customer_Number__c='6548681',TfB_PB_CreditCheckResponse__c='Positive'); insert SourceAcc; csord__Order_Request__c vOrderReq = new csord__Order_Request__c(); vOrderReq.Name='Test Order'; vOrderReq.csord__Module_Name__c='TestModule'; vOrderReq.csord__Module_Version__c='TestVersion'; vOrderReq.TfB_PB_Account__c=SourceAcc.Id; insert vOrderReq; csord__Subscription__c objCS = new csord__Subscription__c (csord__Account__c = SourceAcc.Id,csord__Order_Request__c=vOrderReq.Id,csord__Identification__c='abc',Name= 'test'); insert objCS; /*List<selectOption> options = new List<selectOption>(); options.add('Takeover'); options.add('Move');*/ TfB_PB_AccountActionsWrapper objActWap = new TfB_PB_AccountActionsWrapper(); ApexPages.currentPage().getParameters().put('id',SourceAcc.Id); objActWap.selectedActions='Takeover'; objActWap.Proceed(); objActWap.getDisplayAccount(); //objActWap.ActionValues=; objActWap.getCurrentList(); objActWap.updateSelectedSubscriptions(); objActWap.doSelectItem(); objActWap.doDeselectItem(); objActWap.getSelectedCount(); objActWap.doNext(); objActWap.doPrevious(); objActWap.getHasPrevious(); objActWap.getHasNext(); objActWap.cancel(); objActWap.getTotalPages(); objActWap.getPageNumber(); TfB_PB_AccountActionsWrapper.wrapSubscription AccWrapper = new TfB_PB_AccountActionsWrapper.wrapSubscription(); TfB_PB_AccountActionsWrapper.wrapSubscription AccWrapper1 = new TfB_PB_AccountActionsWrapper.wrapSubscription(objCS); TfB_PB_AccountActionsWrapper.wrapSubscription AccWrapper2 = new TfB_PB_AccountActionsWrapper.wrapSubscription(objCS,'True'); } }
and below is the method from my controller whhich is not getting covered after giving it so much try.
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]; } //Venkat added the below logic 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'){ if(subids.size()>0){ oppList = [select id, Name, AccountId from Opportunity where AccountId=:accountId limit 1]; PageReference pageOpportunity = new PageReference('/'+oppList.Id); pageOpportunity.setRedirect(false); return pageOpportunity; } 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'){ if(subids.size()>0){ oppList = [select id, Name, AccountId from Opportunity where AccountId=:accountId limit 1]; PageReference pageOpportunity = new PageReference('/'+oppList.Id); pageOpportunity.setRedirect(false); return pageOpportunity; } 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{ if(subids.size()>0){ oppList = [select id, Name, AccountId from Opportunity where AccountId=:accountId limit 1]; PageReference pageOpportunity = new PageReference('/'+oppList.Id); pageOpportunity.setRedirect(false); return pageOpportunity; } else{ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'You need to select atleast one subscription'); ApexPages.addMessage(myMsg); return null; } } }
My current code coverage is 50% only and i am not able to increase it further after giving it so much try.Please help me out here to achieve sufficient code coverage.
Many thanks in advance.