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
SFDC Apex DevSFDC Apex Dev 

help me to write test class for the below class...

global class UrlUtils {
    
    global static String getBase(String url){
        String[] split = StringUtils.split(url, '?');
        if(split == null || split.size() == 0){
            return null;
        }
        return split[0];
    }

    global static Map<String,String> getParams(String url){
        //url -> http://google.com?api=x&xyz=123
        Map<String,String> returnMap = new Map<String,String>();
        String[] split = StringUtils.split(url, '?');
        //split -> ['http://google.com','api=x&xyz=123']
        if(split == null || split.size() != 2 || split[1] == null){
            return returnMap;
        }
        split = StringUtils.split(split[1],'&');
        //split -> ['api=x','xyz=123']
        if(split != null && split.size() > 0){
            String[] split2 = null;
            for(String keyValuePair : split){
                //keyValuePair -> 'api=x'
                split2 = StringUtils.split(keyValuePair,'=');
                returnMap.put(
                    (split2 == null || split2.size() < 1 ? '' : split2[0]),
                    EncodingUtil.urlDecode(split2 == null || split2.size() < 2 ? '' : split2[1], 'UTF-8'));
            }
        }
        return returnMap;
    }

    global static String ensureUrlBeginsWithHttp(String url){
        if(StringUtils.isNotEmpty(url)){
            final String lowerCaseUrl = StringUtils.lowerCase(url);
            if(    !StringUtils.startsWith(lowerCaseUrl, 'http://') 
              &&   !StringUtils.startsWith(lowerCaseUrl, 'https://')){
                url = 'http://' 
                    + StringUtils.stripStart(
                        (StringUtils.contains(lowerCaseUrl, '//') 
                            ? StringUtils.substringAfter(url, '//') 
                            : url)
                        ,'/:'
                    );
            }
        }
        return url;
    }

}
Best Answer chosen by SFDC Apex Dev
Raj VakatiRaj Vakati
Try this 
@isTest
    static void testMapNonVipUrl() {
        
        UrlUtils.ensureUrlBeginsWithHttp('google.com');
       
    }