0

I have these two unit tests. The first one passes and the second one returns the null reference error. However, when I look at the stack trace it tells me the following method is causing the null reference:

zuoraContactSync.mergeList();

As this passes the unit test for it and the method does work for it I am not entirely sure why it fails in the second test. lookerById calls upon mergeList and then does some actions to parse the data in it. Why would it fail the reference here? Am I supposed to directly set the List MergeList within the test for it to process correctly?

@isTest Static Void testZuoraMerge() {

Test.startTest();
TestHttpMockFactory s = new TestHttpMockFactory('mock values');
Test.setMock(HttpCalloutMock.class, s);
List<Contact> zuoraContact = new List<Contact>();

zuoraContact = zuoraContactSync.mergeList();
Test.stopTest();
system.assertEquals(2, zuoraContact.size());

}

@isTest static void testLookerById() {

Test.startTest();
TestHttpMockFactory s = new TestHttpMockFactory('mock values');
Test.setMock(HttpCalloutMock.class, s);
Map<Id, List<Contact>> lookerById = zuoraContactSync.lookerById();
Test.stopTest();

system.assert(!lookerById.isEmpty());                                              
}

This is the method that returns a null reference:

public static List<Contact> mergeList(){
    List<Contact> lookerList = zuoraContactSync.zuoraContactData();
    List<Contact> lookerAddList = zuoraContactSync.zuoraAddConData();
    List<Contact> result = new List<Contact>();
    result.addAll(lookerList);
    result.addAll(lookerAddList);

    return result;  
}

The Lists are being created out of the httpmock responses.

  • 1
    Welcome to SFSE! Please edit this question to provide a clear, complete example of the code that fails. There's going to be no way to diagnose this issue without seeing the code that is running. – David Reed Sep 5 at 23:33
  • is zuoracontactsync.mergelist an object method or a class method? what values does it expect? you should use edit to post the essentials of this method – cropredy Sep 5 at 23:34
0

I solved this by setting up more data in @TestSetup and then changing the method to take a List parameter, so I could just pass it whatever.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.