+ Start a Discussion
uHaveOptionsuHaveOptions 

Code Coverage 44% 13/29 what am I missing?

Here is my Apex Class.  It's a convert button from Proposal Object to Listing Object.
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;
    }      
}

This is my test class.  What else am I missing? 
@isTest(SeeAllData=true)
public class ControllerProposalConvertViewTest {
    
    static testMethod void convert(){
        Proposal__c p = new Proposal__c (Name = 'Test Name', Already_Converted__c = 'Converted',Property__c = 'a007A000001C6CM',Zoning__c = 'Zone',Lease_Type__c = 'Monthly',Lease_Notes__c = 'Ground Lease',Lot_Size__c = 100.00,Lot__c = 50.00,Cap_Rate__c = 512.75,Year_Built__c = '1975',Term__c = 456,NOI__c = 123.12,Years_Remaining__c = 10.50,Lease_Commencement_Date__c = date.Today(),Rent_Commencement_Date__c = date.Today(),Lease_Expiration_Date__c = date.Today(),Square_Footage__c = 50000);
        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 Name', Already_Converted__c = 'Not Converted',Property__c = 'a007A000001C6CM',Zoning__c = 'Zone',Lease_Type__c = 'Monthly',Lease_Notes__c = 'Ground Lease',Lot_Size__c = 100.00,Lot__c = 50.00,Cap_Rate__c = 512.75,Year_Built__c = '1975',Term__c = 456,NOI__c = 123.12,Years_Remaining__c = 10.50,Lease_Commencement_Date__c = date.Today(),Rent_Commencement_Date__c = date.Today(),Lease_Expiration_Date__c = date.Today(),Square_Footage__c = 50000);
        PageReference retPage = Page.ProposalConvertView2;
        Test.setCurrentPage(retPage); 
        ApexPages.currentPage().getHeaders().get('sServerName');
        cont.back();
        
        
        
        
        }
       }
NOTE:  The ones underlined in my APEX are the ones not being counted or in the developer console is not passing.  Can you advice me what I'm missing?
 
Best Answer chosen by uHaveOptions
RAM AnisettiRAM Anisetti
Hi,
try this one
 
@isTest(SeeAllData=true)
public class ControllerProposalConvertViewTest {
    
       static testMethod void convert(){
	   
	   
        Proposal__c p = new Proposal__c (
		Name = 'Test Name', 
		Already_Converted__c = 'Converted',
		Property__c = 'a007A000001C6CM',
		Zoning__c = 'Zone',
		Lease_Type__c = 'Monthly',
		Lease_Notes__c = 'Ground Lease',
		Lot_Size__c = 100.00,
		Lot__c = 50.00,
		Cap_Rate__c = 512.75,
		Year_Built__c = '1975',
		Term__c = 456,
		NOI__c = 123.12,
		Years_Remaining__c = 10.50,
		Lease_Commencement_Date__c = date.Today(),
		Rent_Commencement_Date__c = date.Today(),
		Lease_Expiration_Date__c = date.Today(),
		Square_Footage__c = 50000);
		
		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 Name', Already_Converted__c = 'Not Converted',Property__c = 'a007A000001C6CM',Zoning__c = 'Zone',Lease_Type__c = 'Monthly',Lease_Notes__c = 'Ground Lease',Lot_Size__c = 100.00,Lot__c = 50.00,Cap_Rate__c = 512.75,Year_Built__c = '1975',Term__c = 456,NOI__c = 123.12,Years_Remaining__c = 10.50,Lease_Commencement_Date__c = date.Today(),Rent_Commencement_Date__c = date.Today(),Lease_Expiration_Date__c = date.Today(),Square_Footage__c = 50000);
        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 Name', 
		Already_Converted__c = 'Not Converted',
		Property__c = 'a007A000001C6CM',
		Zoning__c = 'Zone',
		Lease_Type__c = 'Monthly',
		Lease_Notes__c = 'Ground Lease',
		Lot_Size__c = 100.00,
		Lot__c = 50.00,
		Cap_Rate__c = 512.75,
		Year_Built__c = '1975',
		Term__c = 456,
		NOI__c = 123.12,
		Years_Remaining__c = 10.50,
		Lease_Commencement_Date__c = date.Today(),
		Rent_Commencement_Date__c = date.Today(),
		Lease_Expiration_Date__c = date.Today(),
		Square_Footage__c = 50000);
		
		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 Name', Already_Converted__c = 'Not Converted',Property__c = 'a007A000001C6CM',Zoning__c = 'Zone',Lease_Type__c = 'Monthly',Lease_Notes__c = 'Ground Lease',Lot_Size__c = 100.00,Lot__c = 50.00,Cap_Rate__c = 512.75,Year_Built__c = '1975',Term__c = 456,NOI__c = 123.12,Years_Remaining__c = 10.50,Lease_Commencement_Date__c = date.Today(),Rent_Commencement_Date__c = date.Today(),Lease_Expiration_Date__c = date.Today(),Square_Footage__c = 50000);
        insert c;
		
		PageReference retPage = Page.ProposalConvertView2;
        Test.setCurrentPage(retPage); 
        ApexPages.currentPage().getHeaders().get('sServerName');
        cont.back();
        
        
        
        
        }
		
       }

 

All Answers

RAM AnisettiRAM Anisetti
Hi,
try this one
 
@isTest(SeeAllData=true)
public class ControllerProposalConvertViewTest {
    
       static testMethod void convert(){
	   
	   
        Proposal__c p = new Proposal__c (
		Name = 'Test Name', 
		Already_Converted__c = 'Converted',
		Property__c = 'a007A000001C6CM',
		Zoning__c = 'Zone',
		Lease_Type__c = 'Monthly',
		Lease_Notes__c = 'Ground Lease',
		Lot_Size__c = 100.00,
		Lot__c = 50.00,
		Cap_Rate__c = 512.75,
		Year_Built__c = '1975',
		Term__c = 456,
		NOI__c = 123.12,
		Years_Remaining__c = 10.50,
		Lease_Commencement_Date__c = date.Today(),
		Rent_Commencement_Date__c = date.Today(),
		Lease_Expiration_Date__c = date.Today(),
		Square_Footage__c = 50000);
		
		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 Name', Already_Converted__c = 'Not Converted',Property__c = 'a007A000001C6CM',Zoning__c = 'Zone',Lease_Type__c = 'Monthly',Lease_Notes__c = 'Ground Lease',Lot_Size__c = 100.00,Lot__c = 50.00,Cap_Rate__c = 512.75,Year_Built__c = '1975',Term__c = 456,NOI__c = 123.12,Years_Remaining__c = 10.50,Lease_Commencement_Date__c = date.Today(),Rent_Commencement_Date__c = date.Today(),Lease_Expiration_Date__c = date.Today(),Square_Footage__c = 50000);
        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 Name', 
		Already_Converted__c = 'Not Converted',
		Property__c = 'a007A000001C6CM',
		Zoning__c = 'Zone',
		Lease_Type__c = 'Monthly',
		Lease_Notes__c = 'Ground Lease',
		Lot_Size__c = 100.00,
		Lot__c = 50.00,
		Cap_Rate__c = 512.75,
		Year_Built__c = '1975',
		Term__c = 456,
		NOI__c = 123.12,
		Years_Remaining__c = 10.50,
		Lease_Commencement_Date__c = date.Today(),
		Rent_Commencement_Date__c = date.Today(),
		Lease_Expiration_Date__c = date.Today(),
		Square_Footage__c = 50000);
		
		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 Name', Already_Converted__c = 'Not Converted',Property__c = 'a007A000001C6CM',Zoning__c = 'Zone',Lease_Type__c = 'Monthly',Lease_Notes__c = 'Ground Lease',Lot_Size__c = 100.00,Lot__c = 50.00,Cap_Rate__c = 512.75,Year_Built__c = '1975',Term__c = 456,NOI__c = 123.12,Years_Remaining__c = 10.50,Lease_Commencement_Date__c = date.Today(),Rent_Commencement_Date__c = date.Today(),Lease_Expiration_Date__c = date.Today(),Square_Footage__c = 50000);
        insert c;
		
		PageReference retPage = Page.ProposalConvertView2;
        Test.setCurrentPage(retPage); 
        ApexPages.currentPage().getHeaders().get('sServerName');
        cont.back();
        
        
        
        
        }
		
       }

 
This was selected as the best answer
uHaveOptionsuHaveOptions
Thanks RAM that one brought it to 93%.  I'll try to upload now.  Thanks again