Getting the error after running the test, and the code coverage for the class is 73%. I would appreciate if you could point me in the right direction.
Class and the test class is below for your reference:
Class
public with sharing class FSWLeadIntegrationController
{
// This controller class allows for the transmission of new lead account and contact data to the admin application for integration.
//
private static final String NEWACCOUNTID_URL_PARAM = 'newAccountId';
private static final String NEWCONTACTID_URL_PARAM = 'newContactId';
private static final String NEWOPPORTUNITYID_URL_PARAM = 'newOpportunityId';
private static final String NEWSITE_URL_PARAM = 'newSite';
public Id newAccountId = null;
public Id newContactId = null;
public Id newOpportunityId = null;
public string newSite = null;
public FSWLeadIntegrationController()
{
System.Debug('FSWLeadIntegrationController: I am here DEFAULT>>');
}
public FSWLeadIntegrationController(ApexPages.StandardController controller)
{
newAccountId = System.currentPageReference().getParameters().get(NEWACCOUNTID_URL_PARAM);
newContactId = System.currentPageReference().getParameters().get(NEWCONTACTID_URL_PARAM);
newOpportunityId = System.currentPageReference().getParameters().get(NEWOPPORTUNITYID_URL_PARAM);
newSite = System.currentPageReference().getParameters().get(NEWSITE_URL_PARAM);
newSite = newSite == null ? 'Fsw' : newSite;
System.Debug('FSWLeadIntegrationController: I am here 2>>' + newSite);
}
public PageReference NewLeadIntegration()
{
System.Debug('FSWLeadIntegrationController: I am here NewLeadIntegration>>');
SendAccountAndContact(newAccountId, newContactId, newSite);
PageReference redirectPage = null;
if (newOpportunityId == null)
{
redirectPage = new PageReference('/'+ newAccountId);
}
else
{
redirectPage = new PageReference('/'+ newOpportunityId);
}
redirectPage.setRedirect(true);
return redirectPage;
}
public static void SendAccountAndContact (Id newAccountId, Id newContactId, String newSite)
{
if(!LeadHelper.UseLeadIntegration())
{
System.Debug('Not using FswLeadIntegration');
return;
}
// Used to provide data to the admin application.
AdminIntegration admin = DependencyManager.getAdminIntegration();
// Pass id to admin for integration async
admin.insertAccountAndContact(newAccountId, newContactId, newSite);
}
}
Test Class:
@isTest
private class FSWLeadIntegrationControllerTest {
// This class tests the New Lead Integration Controller.
//
private static string TEST_PAGE_URL = '';
public static testMethod void FSWLeadIntegrationControllertest()
{
Lead testLead = new Lead();
FSWLeadIntegrationController fswLeadIntegrationController = new FSWLeadIntegrationController(new ApexPages.StandardController(testLead));
testLead.Contact_Site__c = 'FSW';
PageReference fswLeadIntegrationPageRef = Page.FSWLeadIntegration;
Test.setCurrentPageReference(fswLeadIntegrationPageRef);
Account testAccount = new Account(Name = 'Test Only');
insert(testAccount);
fswLeadIntegrationController.newAccountId = testAccount.Id;
//
Contact testContact = new Contact(Email = '[email protected]', LastName='Test LastName');
insert(testContact);
fswLeadIntegrationController.newContactId = testContact.Id;
//
fswLeadIntegrationController.newOpportunityId = null;
//
PageReference redirectPage = fswLeadIntegrationController.NewLeadIntegration();
System.assertNotEquals(redirectPage.getUrl().substring(0, TEST_PAGE_URL.length()), TEST_PAGE_URL);
}
public static testMethod void SendAccountAndContactTest()
{
PageReference fswLeadIntegrationPageRef = Page.FSWLeadIntegration;
Test.setCurrentPageReference(fswLeadIntegrationPageRef);
Lead testLead = new Lead();
testLead.Contact_Site__c = 'FSW';
Account testAccount = new Account(Name = 'Test Only');
insert(testAccount);
//
Contact testContact = new Contact(Email = '[email protected]', LastName='Test LastName');
insert(testContact);
//
FSWLeadIntegrationController.SendAccountAndContact(testAccount.Id, testContact.Id, testLead.Contact_Site__c);
}
}