I am writing a unittest for my apex class but get an error System.NullPointerException: Attempt to de-reference a null object on my unittest for variable: testoptions
Apex class
public class WebToObjAttachments {
public date TravelDateIn {get;set;}
public date TravelDateOut {get;set;}
public class ApplicationException extends Exception {}
private final Lead weblead;
public string recordtype{get;set;}
public List<Attachment> attachments {get; set;}
public List<Attachment> newAttachments {get; set;}
public string recordtypetext {get;set;}
public blob file { get; set; }
public string urlvalue=Apexpages.currentPage().getUrl();
..
public List<SelectOption> CountryOptions {
get {
List<SelectOption> options = new List<SelectOption>();
if(!urlvalue.contains('_NL')){
options.add(new SelectOption('NL', 'Netherlands'));
for (Schema.PicklistEntry pe : SObjectType.Lead.fields.CountryCode.getPicklistValues()) {
}
options.add(new SelectOption('BE', 'Belgium'));
options.add(new SelectOption('FR', 'France'));
options.add(new SelectOption('DE', 'Germany'));
options.add(new SelectOption('ES', 'Spain'));
options.add(new SelectOption('PT', 'Portugal'));
options.add(new SelectOption('IT', 'Italy'));
options.add(new SelectOption('GB', 'United Kingdom'));
options.add(new SelectOption('SCOT', 'Scotland'));
options.add(new SelectOption('IE', 'Ireland'));
options.add(new SelectOption('US', 'United States'));
}
return options;
}
set;}
..
}
Unittest
private static testMethod void CountryOptionsTest()
{
property__c prop = new property__c();
prop.name = 'Testproperty';
insert prop;
Lead le=new Lead(Lastname='Unit Test', RecordType__c = 'Guest');
insert le;
ApexPages.StandardController sc = new ApexPages.standardController(le);
WebToObjAttachments controller = new WebToObjAttachments(sc);
PageReference pageRef = Page.WebToObjAttachment_NL;
Test.startTest();
Test.setCurrentPage(pageRef);
List<SelectOption> testoptions = controller.CountryOptions ;
Test.stopTest();
}
Bebug on urlvalue returms null what am I doing wrong.
Blockquote