I have a Code Coverage Failure of 32% I already tested my APEX Class and it's coming out as 27/29 at 93%. I do have the following...
ControllerProposalConvertView = Apex Class
Convert = Custom Link
ConvertView = VF Page
ConvertView2 = VF Page
ControllerProposalConvertViewTest4 = @isTest
What am I missing here? Here are my codes.
ControllerProposalConvertView
public class ControllerProposalConvertView {
public Id pId;
public String convertedAccountId;
public ControllerProposalConvertView(ApexPages.StandardController stdController){
pId = ApexPages.CurrentPage().getParameters().get('id');
System.Debug('#######leadId:' + pId);
}
public PageReference convert(){
try{
Proposal__c p = [SELECT Id, name, Already_Converted__c, Property__c, Square_Footage__c, Lot_Size__c, Lot__c, Cap_Rate__c, Year_Built__c, Zoning__c, Term__c, Lease_Type__c, NOI__c, Lease_Commencement_Date__c, Rent_Commencement_Date__c, Lease_Expiration_Date__c, Years_Remaining__c, Lease_Notes__c FROM Proposal__c WHERE Id=:pId LIMIT 1];
if (p.Already_Converted__c =='Not Converted'){
Listing__c c=new Listing__c(Name=p.Name, Property__c=p.Property__c, Square_Footage__c=p.Square_Footage__c, Lot_Size__c=p.Lot_Size__c, Lot__c=p.Lot__c, Cap_Rate__c=p.Cap_Rate__c, Year_Built__c=p.Year_Built__c, Zoning__c=p.Zoning__c, Term__c=p.Term__c, Lease_Type__c=p.Lease_Type__c, NOI__c=p.NOI__c, Lease_Commencement_Date__c=p.Lease_Commencement_Date__c, Rent_Commencement_Date__c=p.Rent_Commencement_Date__c, Lease_Expiration_Date__c=p.Lease_Expiration_Date__c, Years_Remaining__c=p.Years_Remaining__c, Lease_Notes__c=p.Lease_Notes__c);
System.Debug('#######c :' + c );
insert c;
p.Already_Converted__c='Converted';
update p;
convertedAccountId = c.Id;
System.Debug('#######convertedAccountId :' + convertedAccountId );
}
else{
String sServerName = ApexPages.currentPage().getHeaders().get('Host');
sServerName = 'https://'+sServerName+'/';
PageReference retPage = new PageReference(sServerName + '/apex/ProposalConvertView2?id='+ pId);
retPage.setRedirect(true);
System.Debug('#######ALREADYCONVERTED' );
return retPage;
}
}
catch(Exception e){
System.Debug('#######Error - Exception [' + e.getMessage() + ']');
return null;
}
String sServerName = ApexPages.currentPage().getHeaders().get('Host');
sServerName = 'https://'+sServerName+'/';
System.Debug('#######sServerName :' + sServerName );
PageReference retPage = new PageReference(sServerName + convertedAccountId);
System.Debug('#######retPage :' + retPage );
retPage.setRedirect(true);
return retPage;
}
public PageReference back(){
String sServerName = ApexPages.currentPage().getHeaders().get('Host');
sServerName = 'https://'+sServerName+'/';
System.Debug('#######sServerName :' + sServerName );
PageReference retPage = new PageReference(sServerName + pId);
System.Debug('#######retPage :' + retPage );
retPage.setRedirect(true);
return retPage;
}
}
ControllerProposalConvertViewTest4
@isTest
public class ControllerProposalConvertViewTest4 {
static testMethod void convert(){
Proposal__c p = new Proposal__c (
Name = 'Test Tes',
Already_Converted__c = 'Converted',
Property__c = 'a007A000001C6CM',
Zoning__c = 'Zones',
Lease_Type__c = 'Monthly',
Lease_Notes__c = 'Ground Lease',
Lot_Size__c = 999.00,
Lot__c = 99.00,
Cap_Rate__c = 999.75,
Year_Built__c = '1999',
Term__c = 999,
NOI__c = 999.12,
Years_Remaining__c = 99.50,
Lease_Commencement_Date__c = date.Today(),
Rent_Commencement_Date__c = date.Today(),
Lease_Expiration_Date__c = date.Today(),
Square_Footage__c = 99900);
insert p;
PageReference pageRef = Page.ProposalConvertView;
Test.setCurrentPage(pageRef);
ApexPages.currentPage().getParameters().put('id',p.Id);
ApexPages.StandardController std = new ApexPages.StandardController(new Proposal__c());
ControllerProposalConvertView cont = new ControllerProposalConvertView (std);
Id pId;
cont.convert();
listing__c c = new listing__c (Name = 'Test Tes',
Already_Converted__c = 'Converted',
Property__c = 'a007A000001C6CM',
Zoning__c = 'Zones',
Lease_Type__c = 'Monthly',
Lease_Notes__c = 'Ground Lease',
Lot_Size__c = 999.00,
Lot__c = 99.00,
Cap_Rate__c = 999.75,
Year_Built__c = '1999',
Term__c = 999,
NOI__c = 999.12,
Years_Remaining__c = 99.50,
Lease_Commencement_Date__c = date.Today(),
Rent_Commencement_Date__c = date.Today(),
Lease_Expiration_Date__c = date.Today(),
Square_Footage__c = 99900);
insert c;
PageReference retPage = Page.ProposalConvertView2;
Test.setCurrentPage(retPage);
ApexPages.currentPage().getHeaders().get('sServerName');
cont.back();
}
static testMethod void converttwo(){
Proposal__c p1 = new Proposal__c (
Name = 'Test Tes',
Already_Converted__c = 'Not Converted',
Property__c = 'a007A000001C6CM',
Zoning__c = 'Zones',
Lease_Type__c = 'Monthly',
Lease_Notes__c = 'Ground Lease',
Lot_Size__c = 999.00,
Lot__c = 99.00,
Cap_Rate__c = 999.75,
Year_Built__c = '1999',
Term__c = 999,
NOI__c = 999.12,
Years_Remaining__c = 99.50,
Lease_Commencement_Date__c = date.Today(),
Rent_Commencement_Date__c = date.Today(),
Lease_Expiration_Date__c = date.Today(),
Square_Footage__c = 99900);
insert p1;
PageReference pageRef = Page.ProposalConvertView;
Test.setCurrentPage(pageRef);
ApexPages.currentPage().getParameters().put('id',p1.Id);
ApexPages.StandardController std = new ApexPages.StandardController(new Proposal__c());
ControllerProposalConvertView cont = new ControllerProposalConvertView (std);
Id pId;
cont.convert();
listing__c c = new listing__c (Name = 'Test Tes',
Already_Converted__c = 'Not Converted',
Property__c = 'a007A000001C6CM',
Zoning__c = 'Zones',
Lease_Type__c = 'Monthly',
Lease_Notes__c = 'Ground Lease',
Lot_Size__c = 999.00,
Lot__c = 99.00,
Cap_Rate__c = 999.75,
Year_Built__c = '1999',
Term__c = 999,
NOI__c = 999.12,
Years_Remaining__c = 99.50,
Lease_Commencement_Date__c = date.Today(),
Rent_Commencement_Date__c = date.Today(),
Lease_Expiration_Date__c = date.Today(),
Square_Footage__c = 99900);
insert c;
PageReference retPage = Page.ProposalConvertView2;
Test.setCurrentPage(retPage);
ApexPages.currentPage().getHeaders().get('sServerName');
cont.back();
}
}
ConvertView
<apex:page standardController="Proposal__c" extensions="ControllerProposalConvertView">
<apex:outputPanel layout="block" style="font-weight:bold">
You are about to convert this proposal to a listing. Are you sure you want to do this?
</apex:outputPanel>
<apex:form >
<apex:commandButton action="{!convert}" value="OK" id="OK" rerender="hiddenBlock"/>
<apex:commandButton action="{!back}" value="Cancel" id="Cancel" />
<!-- <apex:commandButton value="Cancel" id="Cancel" onclick="window.alert('You have already created a Listing from this Proposal. Please Press cancel to return to the Proposal page')"/>-->
</apex:form>
<apex:outputPanel layout="block" style="font-weight:bold"> </apex:outputPanel>
</apex:page>
ConvertView2
<apex:page standardController="Proposal__c" extensions="ControllerProposalConvertView">
<apex:outputPanel layout="block" style="font-weight:bold; color:red;">
This proposal has already been converted to a listing. Please click the button below to return to your proposal.
</apex:outputPanel>
<apex:form >
<apex:commandButton action="{!back}" value="Back" id="Cancel"/>
</apex:form>
Convert
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<webLinks>
<fullName>ConvertCustom</fullName>
<availability>online</availability>
<displayType>button</displayType>
<encodingKey>UTF-8</encodingKey>
<linkType>url</linkType>
<masterLabel>Convert</masterLabel>
<openType>replace</openType>
<protected>false</protected>
<url>/apex/ProposalConvertView?id={!Proposal__c.Id}</url>
</webLinks>
I'm just a bit confused. Thanks for looking and your ideas are greatly appreciated.