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
Neha KakrooNeha Kakroo 

Covering Sort Method in test class

Can somebody pls tell me hoe can I cobe the sort method in the test class;

 

public List<SelectOption> Sort(List<SelectOption> lstToSort)
    {
        System.Debug('Original List: ' + lstToSort);
        List<SelectOption> returnList = new List<SelectOption>();
        try
        {
            // Convert SelectOption list To String List
            List<String> convertedList = new List<String>();
            for(SelectOption opt: lstToSort)
            {
                convertedList.add(opt.getLabel()); 
            }
    
            convertedList = sortList(convertedList);
            System.Debug('Convert and Sorted: ' + convertedList);
    
            // Convert String List to SelectOption list
            for(String strOpt: convertedList)
            {
                returnList.add(new SelectOption(strOpt,strOpt)); 
            }
            System.Debug('Returning: ' + returnList);
        }
        catch(Exception exp)
        {
            System.Debug('Exception in Sort(): ' + exp.getMessage());
        }
        return returnList;
    }

UVUV

Call the sort method along with OptionList as a argument from the test class.