+ Start a Discussion
Sai Ram 118Sai Ram 118 

Code coverage for class ?

Hi
Help me with test class

public with sharing class ForecastArchiveController {
    public String userInfo {get; private set;}
    public ForecastArchiveController() {
        setUserDetails(this);
    }
    
    public static void setUserDetails(ForecastArchiveController controller) {
        User userDetail = [SELECT Id, Name, Forecast_OA_Region_Name__c, Forecast_OA_Region_Id__c, UserRole.Name, Profile.Name FROM User WHERE Id =: UserInfo.getUserId()];
        UserWrapper userWrap = new UserWrapper(userDetail);
        controller.userInfo = JSON.serialize(userWrap);
    }

    public class UserWrapper {
        public String userName;
        public String userId;
        public String userForecastOARegion;
        public String userForecastOARegionId;
        public String userRole;
        public String userProfile;

        public UserWrapper(User user) {
            this.userName = user.Name;
            this.userId = user.Id;
            this.userForecastOARegion = user.Forecast_OA_Region_Name__c;
            this.userForecastOARegionId = user.Forecast_OA_Region_Id__c;
            this.userRole = user.UserRole.Name;
            this.userProfile = user.Profile.Name;
        }
    }
}
Steven NsubugaSteven Nsubuga
@isTest
public class ForecastArchiveControllerTest {

    @isTest static void test(){
        
        ForecastArchiveController controller = new  ForecastArchiveController(); 
        System.assert(controller.userInfo != null);    
    }
}