Nieoczekiwany wyjątek zerowego wskaźnika w testowaniu
piszę test jednostkowy usługi odpoczynku w wierzchołku
Moja klasa testowa to
global class Feedpost9 {
// your methods here...
static testMethod void testRest() {
// set up the request object
System.RestContext.request = new RestRequest();
RestContext.request.requestURI = '/v.9/notifications/preferences/ritesh';
// Invoke the method directly
Member__c member=new Member__c(name='ritesh');
insert member;
Notification_Settings__c no=new Notification_Settings__c(member__c=member.Id);
no.Event__c='Category|Cloud Foundry' ;
no.Event_Per_Member__c='12';
insert no;
NotificationRestService.retrievingNotificationSettings();
RestContext.request.requestURI = '/v.9/notifications/preferences' ;
NotificationRestService.retrievingNotificationSettings();
RestContext.request.requestURI ='/v.9/notifications/preferences/ritesh.xml';
NotificationRestService.retrievingNotificationSettings();
}
}
kiedy jednostka testowa osiągnie w tym momencie błąd, otrzymałem błąd RestContext.request.requestURI = '/v.9/notifications/preferences';
NotificationRestService.retrievingNotificationSettings();
błąd jest
System.NullPointerException: Próba usunięcia odwołania do zerowego obiektu Class.NotificationRestService.retrievingNotificationSettings: linia 46, kolumna 1 Class.Feedpost9.testRest: linia 23, kolumna 1
a segment, w którym otrzymuję ten błąd, jest
List<Notification_Settings__c> note1=[SELECT id,name,Member__r.name,Do_not_Notify__c,Event__c,Event_Per_Member__c,Notification_Method__c from Notification_Settings__c WHERE Member__r.name= :userName Limit 1];
Notification_Settings__c note;
if(note1 !=null )
{if(note1.size() >0)
note=note1.get(0);
}
i błąd jest w linii {if (note1.size ()> 0) nie jestem w stanie obliczyć, czy notatka1 nie jest równa null, to dojdzie do następnej linii, ale w następnym wierszu daje mi błąd, dlaczego notatka1 jest pusta następny linel i przekazywanie najpierw if statement.query powinien zwrócić pustą listę.