I am attempting to write a test class for a very basic controller extension. I cannot seem to get 100% coverage in this method. From the 'Try' statement to the 'Else' statement has no coverage. Any help is greatly appreciated.
public pageReference save() {
if(c.origin_postal_code__c != null || c.destination_postal_code__c != null){
try{ //NO CODE COVERAGE STARTS HERE.
insert c;
apexpages.addmessage(new apexpages.message(apexpages.severity.CONFIRM,'The record has been added'));
}
catch(exception e){
system.debug('The following exception has occurred ' + e.getMessage());
}
string acc = c.account__c;
string con = c.contact__c;
string opp = c.opportunity__c;
c = new custom_object__c();
c.account__c = acc;
c.contact__c = con;
c.opportunity__c = opp;
c.status__c = 'Pending'; //NO CODE COVERAGE ENDS HERE.
}
else{
apexpages.addmessage(new apexpages.message(apexpages.severity.ERROR,'Please enter both zip codes to submit the record'));
}
return null;
}
My test class is as follows:
@istest (seealldata = true)
public class TestEntryTest{
public static TestMethod Void Test1(){
test.starttest();
Test.setCurrentPage(page.record_entry);
ApexPages.StandardController qe = new ApexPages.standardController(new custom_object__c());
record_entry_extension controller = new record_entry_extension(qe);
controller.save();
test.stoptest();
}
}