function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Manvendra Singh Rathore 22Manvendra Singh Rathore 22 

System.NullPointerException: null input to JSON parser test class failing

I am writing a test class, and its failing because of Jason parser nullPointer Error. can someone tell me what is wrong with my code? I need help as soon as possible. 

here is main class : 

=================
public class IDMSIFWUserMapping {
    public static String usermapping(User userRec){
        Userrecord userRecord=new Userrecord();
        //Added as part of IC-2651
        List<User> usr = new List<User>();
        if(String.isNotBlank(userRec.FederationIdentifier)){
            usr = [SELECT Contact.Account.PRMIncludeCompanyInfoInSearchResults__c FROM User WHERE
                    FederationIdentifier=:userRec.FederationIdentifier];
        }

        if(userRec.Id != null) {
            userRecord.Id = userRec.Id;
        }
        userRecord.Email=userRec.Email;
        userRecord.mobilePhone=userRec.MobilePhone;
        userRecord.firstName=userRec.FirstName;
        userRecord.lastName=userRec.LastName;
        userRecord.countryCode=userRec.Country;
        userRecord.languageCode=userRec.IDMS_PreferredLanguage__c;
        //userRecord.Email=userRec.DefaultCurrencyIsoCode;
        userRecord.street=userRec.Street;
        userRecord.city=userRec.City;
        userRecord.zipCode=userRec.PostalCode;
        userRecord.stateOrProvinceCode=userRec.State;//'BJ';
        userRecord.county=userRec.IDMS_County__c;
        userRecord.pOBox=userRec.IDMS_POBox__c;
        userRecord.additionalAddress=userRec.IDMS_AdditionalAddress__c;
        userRecord.middleName=userRec.IDMSMiddleName__c;
        userRecord.salutation=userRec.IDMSSalutation__c;
        userRecord.fax=userRec.Fax;
        userRecord.accountId=userRec.BFO_ACCOUNT_ID__c;
        userRecord.userContext=userRec.IDMS_User_Context__c;
        userRecord.registrationSource=userRec.IDMS_Registration_Source__c;
        userRecord.emailOptIn=userRec.IDMS_Email_opt_in__c;
        if(userRec.IDMSHashedToken__c!=null && userRec.IDMSHashedToken__c!='') userRecord.hashedPin=userRec.IDMSHashedToken__c;
        if(userRec.IDMS_Federated_Id__c!=null && userRec.IDMS_Federated_Id__c!='') userRecord.idmsFederatedId=userRec.IDMS_Federated_Id__c;
        if(userRec.IDMSCompanyFederationIdentifier__c!=null && userRec.IDMSCompanyFederationIdentifier__c!='') userRecord.companyFederatedId=userRec.IDMSCompanyFederationIdentifier__c;
        
        //IC-2525 channel, sub-channel,isPrimaryContact
        userRecord.channel = userRec.Channel__c;
        userRecord.subChannel = userRec.SubChannel__c;
        userRecord.IDMSPrimaryContact = userRec.IDMSPrimaryContact__c;
        userRecord.contactId = userRec.ContactId;
        //Company Details
        userRecord.companyName=userRec.CompanyName;
        userRecord.companyStreet=userRec.Company_Address1__c;
        userRecord.companyCity=userRec.Company_City__c;
        userRecord.companyZipCode=userRec.Company_Postal_Code__c;
        userRecord.companyCountryCode=userRec.Company_Country__c;
        userRecord.companyStateOrProvinceCode=userRec.Company_State__c;//'BJ';
        userRecord.companyPOBox=userRec.IDMSCompanyPoBox__c;
        userRecord.companyCounty=userRec.IDMSCompanyCounty__c;
        userRecord.companyAdditionalAddress=userRec.Company_Address2__c;
        userRecord.classLevel1=userRec.IDMSClassLevel1__c;
        userRecord.classLevel2=userRec.IDMSClassLevel2__c;
        userRecord.marketSegment=userRec.IDMSMarketSegment__c;
        userRecord.marketSubSegment=userRec.IDMSMarketSubSegment__c;
        userRecord.marketServed=userRec.IDMSCompanyMarketServed__c;
        userRecord.employeeSize=userRec.IDMSCompanyNbrEmployees__c;
        userRecord.headquarter=String.Valueof(userRec.IDMSCompanyHeadquarters__c);
        userRecord.annualRevenue=String.Valueof(userRec.IDMSAnnualRevenue__c);
        userRecord.taxIdentificationNumber=userRec.IDMSTaxIdentificationNumber__c;
        userRecord.companyWebsite=userRec.Company_Website__c;
        userRecord.jobTitle=userRec.Job_Title__c;
        userRecord.jobFunction=userRec.Job_Function__c;
        userRecord.workPhone=userRec.Phone;
        userRecord.jobDescription=userRec.IDMSJobDescription__c;
        userRecord.profileLastUpdateSource = userRec.IDMS_Profile_update_source__c;
        //Added as part of IC-2651
        userRecord.companyPhone = userRec.IDMSWorkPhone__c;
        System.debug(userRec.RegistrationAttributes__c);
        userRecord.registrationAttributes=(List<IDMSIFWUserMapping.RegistrationAttributes>) JSON.deserialize(userRec.RegistrationAttributes__c,List<IDMSIFWUserMapping.RegistrationAttributes>.class);
        System.debug(userRecord.registrationAttributes);
        //currency
        //department
        //password
        //userRecord.companyDetails=companyDetails;
        string jsonRequest=JSON.serialize(userRecord,true);
        return jsonRequest;
    }
    
    
    
    public class Userrecord{
        public String Id;
        public string userContext ;
        public string salutation ;
        public string firstName ;
        public string middleName ;
        public string lastName ;
        public string countryCode ;
        public string email ;
        public string mobilePhone ;
        public string languageCode ;
        public string emailOptIn ;
        public string street ;
        public string city ;
        public string zipCode ;
        public string stateOrProvinceCode ;
        public string county ;
        public string pOBox ;
        public string additionalAddress ;
        public string suffix ;
        public string fax ;
        public string accountId ;
        public string registrationSource ;
        public string channel;
        public string subChannel;
        public string contactId;
        public boolean IDMSPrimaryContact;
        //public CompanyDetails companyDetails ;
        public string trustedAdmin;
        public string idmsFederatedId;
        public string hashedPin;
        //public string aboutMe;
        
        public string companyName ;
        public string companyStreet ;
        public string companyCity ;
        public string companyZipCode ;
        public string companyStateOrProvinceCode ;
        public string companyPOBox ;
        public string companyCounty ;
        public string companyCountryCode ;
        public string companyAdditionalAddress ;
        public string companyWebsite ;
        public string classLevel1 ;
        public string classLevel2 ;
        public string marketSegment ;
        public string marketSubSegment ;
        public string marketServed ;
        public string employeeSize ;
        public string department ;
        public string headquarter ;
        public string annualRevenue ;
        public string taxIdentificationNumber ;
        public string jobTitle ;
        public string jobFunction ;
        public string jobDescription ;
        public string workPhone ;
        public string companyFederatedId;
        public string profileLastUpdateSource;
        public String companyPhone;
        public List<RegistrationAttributes> registrationAttributes;

        
    }
    public class RegistrationAttributes {
        public String name;
        public String value;
    }
}
=========================================================
here is the test class for this one : 
=========================================================
@isTest(seeAllData=false)
public class IDMSIFWUserMappingTest {
    @testSetup
    static void createData(){
        Id profileId3 =  [select id from profile where name=:Label.CLR218IDMS003].id;
        Id roleId1 = label.CLDEC13SLS41;
        User ownUser = new User(alias = 'userpass', 
                                    email='manoj00.1234@accenture.com', isActive=true,
                                     emailencodingkey='UTF-8', lastname='Testing',firstName='testing',
                                     languagelocalekey='en_US',localesidkey='en_US', 
                                     profileid = profileId3, 
                                     timezonesidkey='Europe/London', username='testUser26062018@cts.com',
                                     Company_Postal_Code__c='12345',Company_Phone_Number__c='9986995000',
                                     FederationIdentifier ='manoj0001',IDMS_Registration_Source__c = 'Test',
                                     IDMS_User_Context__c = 'Home',IDMS_PreferredLanguage__c= 'en',
                                     IDMS_county__c = 'test',IDMS_Email_opt_in__c = 'Y',
                                     IDMS_POBox__c = '1111',IsIDMSUser__c = true,IDMSUserWithoutPwd_c__c = true,
                                     IDMSPinVerification__c='123456',IDMSNewPhone__c='99999999',useRroleid =roleId1); 
        try{
            insert ownUser;
        }catch(Exception e){
            system.debug('Exception occured - StackTraceString -->'+e.getStackTraceString());
            system.debug('Exception occured - Message -->'+e.getMessage());
        }
    }
    
    public static testMethod void userMappingTest(){
        user user1 = [select id, username,email,MobilePhone,FirstName,LastName,Country,IDMS_PreferredLanguage__c,
                      DefaultCurrencyIsoCode,Street,City,PostalCode,State,IDMS_County__c,IDMS_POBox__c,
                      IDMS_AdditionalAddress__c,IDMSMiddleName__c,IDMSSalutation__c,Fax,BFO_ACCOUNT_ID__c,
                      IDMS_User_Context__c,IDMS_Registration_Source__c,IDMS_Email_opt_in__c,
                      IDMSHashedToken__c,IDMS_Federated_Id__c,IDMSCompanyFederationIdentifier__c,
                      CompanyName,Company_Address1__c,Company_City__c,Company_Postal_Code__c,Company_Country__c,
                      Company_State__c,IDMSCompanyPoBox__c,IDMSCompanyCounty__c,Company_Address2__c,
                      IDMSClassLevel1__c,IDMSClassLevel2__c,IDMSMarketSegment__c,IDMSMarketSubSegment__c,
                      IDMSCompanyMarketServed__c,IDMSCompanyNbrEmployees__c,IDMSCompanyHeadquarters__c,
                      IDMSAnnualRevenue__c,IDMSTaxIdentificationNumber__c,Company_Website__c,Job_Title__c,
                      Job_Function__c,Phone,IDMSJobDescription__c,IDMS_Profile_update_source__c,Channel__c,SubChannel__c,
                      IDMSPrimaryContact__c,ContactId, FederationIdentifier, IDMSWorkPhone__c,RegistrationAttributes__c from 
                      user where username ='testUser26062018@cts.com'];
        if(user1 != null){
            IDMSIFWUserMapping.userMapping(user1);
        }else{
            Id profileId3 =  [select id from profile where name=:Label.CLR218IDMS004].id;
            User ownUser11 = new User(alias = 'userpas1', 
                                    email='gc050710016@mailinator.com', isActive=true,
                                     emailencodingkey='UTF-8', lastname='Testing',firstName='testing',
                                     languagelocalekey='en_US',localesidkey='en_US', 
                                     profileid = profileId3, 
                                     timezonesidkey='Europe/London', username='testUser05072018@cts.com',
                                     Company_Postal_Code__c='12345',Company_Phone_Number__c='9986995000',
                                     FederationIdentifier ='gc0001',IDMS_Registration_Source__c = 'Test',
                                     IDMS_User_Context__c = 'Home',IDMS_PreferredLanguage__c= 'en',
                                     IDMS_county__c = 'test',IDMS_Email_opt_in__c = 'Y',
                                     IDMS_POBox__c = '1111',IsIDMSUser__c = true,IDMSUserWithoutPwd_c__c = true,
                                     IDMSPinVerification__c='123456',IDMSNewPhone__c='99999999'/*,useRroleid =roleId1*/);
            IDMSIFWUserMapping.userMapping(ownUser11);
        }
        
    }
}
Raj VakatiRaj Vakati
You need to insert the user record with the following data ... because you are referring this values in the in the code that causes issue.. make sure you set all the values which are used in code 
 
Id profileId3 =  [select id from profile where name=:Label.CLR218IDMS003].id;
        Id roleId1 = label.CLDEC13SLS41;
        User ownUser = new User(alias = 'userpass', 
                                    email='manoj00.1234@accenture.com', isActive=true,
                                     emailencodingkey='UTF-8', lastname='Testing',firstName='testing',
                                     languagelocalekey='en_US',localesidkey='en_US', 
                                     profileid = profileId3, 
									 MobilePhone ='123123',
									 Country='USA',
									 Street='Tesy' ,
									 City ='san',
									 PostalCode ='123123',
									 State ='CA',
									 IDMSMiddleName__c , IDMSSalutation__c ,Fax , BFO_ACCOUNT_ID__c  , 
 ,IDMSHashedToken__c ,IDMS_Federated_Id__c,IDMSCompanyFederationIdentifier__c ,
       Channel__c , SubChannel__c , IDMSPrimaryContact__c ,ContactId ,
        CompanyName ,Company_Address1__c , 
	 Company_City__c , , Company_Country__c ,
	 Company_State__c ,
	 IDMSCompanyPoBox__c 
	 IDMSCompanyCounty__c
		Company_Address2__c
		IDMSClassLevel1__c
		IDMSClassLevel2__c
		IDMSMarketSegment__c
		IDMSMarketSubSegment__c
		IDMSCompanyMarketServed__c
		IDMSCompanyNbrEmployees__c
		IDMSCompanyHeadquarters__c
		IDMSAnnualRevenue__c
		IDMSTaxIdentificationNumber__c
		Company_Website__c
		Job_Title__c
		Job_Function__c
		Phone
		IDMSJobDescription__c
		IDMS_Profile_update_source__c
		IDMSWorkPhone__c
		RegistrationAttributes__c
									 IDMS_County__c ='USA',
									 IDMS_POBox__c='123123', 
									 IDMS_AdditionalAddress__c='Test' ,
                                     timezonesidkey='Europe/London', username='testUser26062018@cts.com',
                                     Company_Postal_Code__c='12345',Company_Phone_Number__c='9986995000',
                                     FederationIdentifier ='manoj0001',IDMS_Registration_Source__c = 'Test',
                                     IDMS_User_Context__c = 'Home',IDMS_PreferredLanguage__c= 'en',
                                     IDMS_county__c = 'test',IDMS_Email_opt_in__c = 'Y',
                                     IDMS_POBox__c = '1111',IsIDMSUser__c = true,IDMSUserWithoutPwd_c__c = true,
                                     IDMSPinVerification__c='123456',IDMSNewPhone__c='99999999',useRroleid =roleId1); 
        try{
            insert ownUser;
        }catch(Exception e){
            system.debug('Exception occured - StackTraceString -->'+e.getStackTraceString());
            system.debug('Exception occured - Message -->'+e.getMessage());
        }