[SalesForce] Test class throwing argument cannot be null error

I am seeing

System.NullPointerException: Argument cannot be null

in my test class

Below is the controller method that i am trying to cover :

public void Synchsongmethod()

{
    system.debug('synch song method is called');
    List<Cue_Sheet_Sequence__c> recordToVerify=new List<Cue_Sheet_Sequence__c>();
    List<Cue_Sheet_Assignment__c> recordToVerify1=new List<Cue_Sheet_Assignment__c>();
    List<Cue_Sheet_Assignment__c> recordToVerify2=new List<Cue_Sheet_Assignment__c>();
    List<SongCpaJunction__c >songcpalist=new List<SongCpaJunction__c>();
    List<Cue_Sheet_Assignment__c>finallist=new List<Cue_Sheet_assignment__c>();
    set<id> songid= new Set<id>();
    Id composerId, publisherId,ArtistId;

    Id seqIdsynch =Id.ValueOf(sid); // <= getting the error here

    system.debug('seqIdsynch'+sid);
    Cue_Sheet_Sequence__c newRecord =[Select id,song__c,Flagged_for_Delete__c,RapidCue_Delete_Timestamp__c, Verified__c,(Select Id, Flagged_for_Delete__c, Copyright_Holder__c From Cue_Sheet_Sequence_References__r ) from Cue_Sheet_Sequence__c where id =:seqIdsynch and Sequence_Order_No__c!=0];
    system.debug('newRecord '+newRecord );

    // for(Cue_Sheet_Sequence__c record:newRecord){
    newRecord.IsSynch__c=true;
    songid.add(newRecord.song__c);
            recordToVerify.add(newrecord);
    //}
    update recordToVerify;

I am seeing error at this line :

Id seqIdsynch =Id.ValueOf(sid);

Below is my test class:

Static void createData(){
    DataBaseForTest.DataBaseMethod();
    songData =DataBaseForTest.songData ;
    scJunList =DataBaseForTest.scJunList;
    songSeq =DataBaseForTest.songSeq ;
    cpaObjList = DataBaseForTest.cpaObjList;
    songSeq= DataBaseForTest.songSeq;
    cueSheet=DataBaseForTest.caseObj;
    assignList=DataBaseForTest.assignList;
    seg=DataBaseForTest.seg;
    List<String> fR=new List<string>();
    fR.add('a');

    sList.add(cueSheet.Episode__r.show__r);

    seqList.add(songSeq);
    segList.add(seg);

}
static  void updateData(){
    createData();

    Id sid=songseq.id;
    List<Cue_Sheet_Sequence__c> seqList2 =[Select id,song__c,Flagged_for_Delete__c,RapidCue_Delete_Timestamp__c, Verified__c,(Select Id, Flagged_for_Delete__c, Copyright_Holder__c From Cue_Sheet_Sequence_References__r ) from Cue_Sheet_Sequence__c where id =:sid and Sequence_Order_No__c!=0];
    List<Cue_Sheet_Sequence__c> seqListNew1= new List<Cue_Sheet_Sequence__c>();
    List<Cue_Sheet_Assignment__c> assignList2 = new List<Cue_Sheet_Assignment__c>();
    Id cpaAssignRecordTypeId0 = Schema.SObjectType.Cue_Sheet_Assignment__c.getRecordTypeInfosByName().get('Composer').getRecordTypeId();    
    Id cpaAssignRecordTypeId2 = Schema.SObjectType.Cue_Sheet_Assignment__c.getRecordTypeInfosByName().get('Publisher').getRecordTypeId();    

    for(Cue_Sheet_Sequence__c sq:seqList2){
        assignList2.add(new Cue_Sheet_Assignment__c(Flagged_for_Delete__c= false,RecordTypeId=cpaAssignRecordTypeId ,first_name__c='test name',last_NAme__C='last42',society__c='a', Cue_Sheet_Sequence__c=sq.id, Percentage__c = 50.0) );
        assignList2.add(new Cue_Sheet_Assignment__c(Flagged_for_Delete__c= false,RecordTypeId=cpaAssignRecordTypeId1 ,first_name__c='test name',last_NAme__C='last41',society__c='a', Cue_Sheet_Sequence__c=sq.id, Percentage__c = 50.0) );
        sq.Cue_Usage__c='BI';
        sq.No_of_Occurances__c=3;
        sq.Duration__c='12:12';
        sq.verified__c=True;
    }

    insert assignList2;
    update seqList2;


}

static testMethod void InsertMethod4(){

    updateData();
    Test.setCurrentPageReference(new PageReference('Page.CueSheetEdit')); 
    System.currentPageReference().getParameters().put('id', cueSheet.id);
    System.currentPageReference().getParameters().put('Add', '1');
    System.currentPageReference().getParameters().put('seqId', songSeq.id);
    System.currentPageReference().getParameters().put('verifyStatus', 'Verify');
    System.currentPageReference().getParameters().put('seqIdVerify', '0');



    CueSheetEditController obj1=  new CueSheetEditController (new 
          ApexPages.StandardController(cueSheet));
    obj1.verifySong();
    obj1.approveUpdateSheet();
    obj1.scheduleRapidcue();
    obj1.Synchsongmethod();
}

Can anyone please point out where am i going wrong?

Best Answer

Try this way:

Id seqIdSynch = ( Id )sid;

or also check before casting it that sid is not null:

if( sid == null ){ return; }

if this is a private controller property, make it testVisible using:

@testVisible

and be sure to set it in your test method.

if this is being pulled from a field on an object - be sure it is also not null before trying to cast it.

Hope that helps. I don't see all of the code to make a solid answer - just some basic assumptions by what i can see.