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
Shivani Thakur 32Shivani Thakur 32 

write a test class for given class

Shivani Thakur 32Shivani Thakur 32
public class MasterPageWrapper {
    
    public SObjectPageInfoWrapper objParentFieldDetails {get;set;}
    public Map<String,SObjectPageInfoWrapper> childRelatedFieldDetailsMap {get;set;}
    
    public MasterPageWrapper(SObjectPageInfoWrapper objParentFieldDetails, Map<String,SObjectPageInfoWrapper> childRelatedFieldDetailsMap){
        this.objParentFieldDetails = objParentFieldDetails;
        this.childRelatedFieldDetailsMap = childRelatedFieldDetailsMap; 
    }
}
Suraj Tripathi 47Suraj Tripathi 47

Hi Shivani,

Please find the solution. "write a test class for given class".

I think "SObjectPageInfoWrapper" is  also a wrapper but you did not provide us code for this wrapper.

I have written a Test class with 100% coverage. Please take Reference from this code

Class :

public class MasterPageWrapper {
    
    public SObjectPageInfoWrapper objParentFieldDetails {get;set;}
    public Map<String,SObjectPageInfoWrapper> childRelatedFieldDetailsMap {get;set;}
    
    public MasterPageWrapper(SObjectPageInfoWrapper objParentFieldDetails, Map<String,SObjectPageInfoWrapper> childRelatedFieldDetailsMap){
        this.objParentFieldDetails = objParentFieldDetails;
        this.childRelatedFieldDetailsMap = childRelatedFieldDetailsMap; 
    }
    public class SObjectPageInfoWrapper{
        public string name{get;set;}
        public Integer count{get;set;}
        public Account ac;
    }
}


Test Class : 

@isTest
public class MasterPageWrapperTest {

    testMethod static void MasterPageWrapperTest(){
        Account acInstance=new Account();
        acInstance.Name='Test';
        insert acInstance;
        
        MasterPageWrapper.SObjectPageInfoWrapper obj=new MasterPageWrapper.SObjectPageInfoWrapper();
        obj.Name='Data';
        obj.ac=acInstance;
        obj.count=2;
        List<MasterPageWrapper.SObjectPageInfoWrapper> wrapperList=new List<MasterPageWrapper.SObjectPageInfoWrapper>();
        wrapperList.add(obj);
       
       Map<String,MasterPageWrapper.SObjectPageInfoWrapper> childRelatedFieldDetailsMap=new Map<String,MasterPageWrapper.SObjectPageInfoWrapper>();
       childRelatedFieldDetailsMap.put('1',obj);         
        Test.startTest();
        MasterPageWrapper objWrapper=new MasterPageWrapper(obj,childRelatedFieldDetailsMap);
        test.stopTest();
    }
}


Please let me know it is working or not??

If it helps you please mark it as Best Answer so that other people would take reference from it.

Thank You!