+ Start a Discussion
shravani milshravani mil 

Not covering lines

Hi,

i am unable to cover this lines in my test class can any one give me some idea how to do this.


        public Integer compareTo(Object compareTo) {
        
            WRNWrapper compareToWr = (WRNWrapper)compareTo;
            
            Integer returnValue = 0;
            
            if (getDate(this.openedDate) > getDate(compareToWr.openedDate)) {
                returnValue = -1;
            } else if (getDate(this.openedDate) < getDate(compareToWr.openedDate)) {
                returnValue = 1;
            }
        
            return returnValue;       
        }
        
        private DateTime getDate(String dt) {
            
            String[] dt2 = dt.split(' ');
            String[] dtFields = dt2[0].split('/');
            String[] tmFields = dt2[1].split(':');
            return system.Datetime.newInstance(Integer.valueOf(dtFields[2]), Integer.valueOf(dtFields[0]), Integer.valueOf(dtFields[1]), 
                                                Integer.valueOf(tmFields[0]), Integer.valueOf(tmFields[1]), Integer.valueOf(tmFields[2]));
        }
    }
}

Thanks.
Best Answer chosen by shravani mil
Tarun_KhandelwalTarun_Khandelwal
Hi Shravani,

Sorry for Inconvenience. Please try this.


List<WRNWrapper> wrnWrapperTestList = new List<WRNWrapper>();
wrnWrapperTestList.add(new WRNWrapper('07/07/2014 08:35:55'));
wrnWrapperTestList.add(new WRNWrapper('07/07/2020 08:35:55'));
wrnWrapperTestList.add(new WRNWrapper('07/09/2015 08:35:55'));
wrnWrapperTestList.add(new WRNWrapper('07/09/2015 08:35:55'));
wrnWrapperTestList.sort();
system.assertEquals(wrnWrapperTestList[1].openedDate, '07/09/2015 08:35:55');


We can't add String directly to the WRNWrapper type list. So convert String into WRNWrapper Type. Please let me know in case of any query.
 

All Answers

Tarun_KhandelwalTarun_Khandelwal
Hi Shravani,

Sorry for Inconvenience. Please try this.


List<WRNWrapper> wrnWrapperTestList = new List<WRNWrapper>();
wrnWrapperTestList.add(new WRNWrapper('07/07/2014 08:35:55'));
wrnWrapperTestList.add(new WRNWrapper('07/07/2020 08:35:55'));
wrnWrapperTestList.add(new WRNWrapper('07/09/2015 08:35:55'));
wrnWrapperTestList.add(new WRNWrapper('07/09/2015 08:35:55'));
wrnWrapperTestList.sort();
system.assertEquals(wrnWrapperTestList[1].openedDate, '07/09/2015 08:35:55');


We can't add String directly to the WRNWrapper type list. So convert String into WRNWrapper Type. Please let me know in case of any query.
 
This was selected as the best answer
Tarun_KhandelwalTarun_Khandelwal
Hi Shravani,

Please add constructor in your main class as I told you earlier. 


1. Please Make Constructor of WRNWrapper Class if you don't have like -
    
    public String openedDate;
    public WRNWrapper(String dt) {
        this.openedDate = dt;
    }

And Run the test class. If still you have problem, Please copy whole code of your class here. 

Thanks.