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
sumit pawarsumit pawar 

Test class for below apex not getting enough code coverage

i want to create test class for below apex class... i have created test class but its giving only 64% code coverage...
Please help to create test class for below apex class...

bold lines shows code not covered...

Apex class:

public with sharing class StageUpdateInformation {
    //public Opportunity oop {get;set;}
    //public string Hour {get;set;}
    //public string Minute {get;set;}
    //public list<SelectOption> UserList{get;set;}
    //public list<SelectOption> SelectedUserList{get;set;}
    public list<WrapperStage> wrapperList{get;set;}
   
    public StageUpdateInformation(){
        //oop = new Opportunity();
        wrapperList = new list<WrapperStage>();
        list<string> stlist = OppStagesUtility.oppStage();
        for(string s :stlist){
            wrapperList.add(new WrapperStage(s));
        }
        /*SelectedUserList = new list<SelectOption>();
        list<User> usList = [select Id, Name from User];
        UserList = new list<SelectOption>();
        for(User u:usList){
            UserList.add(new SelectOption(u.Id, u.Name));
        }*/
    }
   
    public Pagereference save(){
        string idNew = '';
        string nameNew = '';
        list<Stage_Update_Information__c> stgUpList = new list<Stage_Update_Information__c>();
        list<string> existStagelist = new list<string>();
        for(WrapperStage wc :wrapperList){
            if(wc.SelectedUserList.size()>0){
                system.debug('============wc.SelectedUserList================'+wc.SelectedUserList);
                system.debug('============wc.Stage================'+wc.Stage);
                existStagelist.add(wc.stage);
                for(SelectOption s :wc.SelectedUserList){
                    if(idNew == ''){
                        idNew += s.getValue();
                        nameNew += s.getLabel();

                    }
                    else{
                        idNew += ','+s.getValue();
                        nameNew += ','+s.getLabel();

                    }
                }
                if(idNew != ''){
                    Stage_Update_Information__c sui = new Stage_Update_Information__c();
                    sui.Owner_Name__c = nameNew;
                    sui.Owner_Id__c = idNew;
                    sui.Stage_Name__c = wc.stage;
                    sui.Hour__c = wc.Hour;
                    sui.Minute__c = wc.Minute;
                    stgUpList.add(sui);

                }
            }
        }
        list<Stage_Update_Information__c> suiList = [select Id, Stage_Name__c from Stage_Update_Information__c where Stage_Name__c IN :existStagelist];
        if(suiList.size()>0){
            delete suiList;
        }
        insert stgUpList; 
        /*string idNew = '';
        string nameNew = '';
        for(SelectOption s :SelectedUserList){
            if(idNew == ''){
                idNew += s.getValue();
                nameNew += s.getLabel();
            }
            else{
                idNew += ','+s.getValue();
                nameNew += ','+s.getLabel();
            }
        }*/
        //system.debug('===============Id list Final============'+idNew);
       
    }
    public class WrapperStage{
        public string stage {get;set;}
        public list<SelectOption> UserList{get;set;}
        public list<SelectOption> SelectedUserList{get;set;}
        //public Opportunity oop {get;set;}
        public string Hour {get;set;}
        public string Minute {get;set;}
       
        public WrapperStage(string s){
            stage = s;
            SelectedUserList = new list<SelectOption>();
            list<User> usList = [select Id, Name from User];
            UserList = new list<SelectOption>();
            for(User u:usList){
                UserList.add(new SelectOption(u.Id, u.Name));
            }
        }
    }
}
Test class:

@isTest
private class TestStageUpdateInformation {

    static testMethod void myUnitTest() {
        StageUpdateInformation Stageupdate = new StageUpdateInformation();
  Stageupdate.save();

       
    }
}