Skip to main content
Vemana Swarna Rama 님이 #Ask An Expert에 질문했습니다
Hi , Can any body help me to write the test class for my class.Thansk in advance.

 

public class VerifyDate {

 

    

 

    //method to handle potential checks against two dates

 

    public static Date CheckDates(Date date1, Date date2) {

 

        //if date2 is within the next 30 days of date1, use date2.  Otherwise use the end of the month

 

        if(DateWithin30Days(date1,date2)) {

 

            return date2;

 

        } else {

 

            return SetEndOfMonthDate(date1);

 

        }

 

    }

 

    

 

    //method to check if date2 is within the next 30 days of date1

 

    private static Boolean DateWithin30Days(Date date1, Date date2) {

 

        Date date30Days = date1.addDays(30); //create a date 30 days away from date1

 

        if( date2 > date30Days ) { return false; }

 

        else { return true; }

 

    }

 

    //method to return the end of the month of a given date

 

    private static Date SetEndOfMonthDate(Date date1) {

 

        Integer totalDays = Date.daysInMonth(date1.year(), date1.month());

 

        Date lastDay = Date.newInstance(date1.year(), date1.month(), totalDays);

 

        return lastDay;

 

    }

 

}
답변 3개
  1. 2015년 7월 2일 오전 10:07
    Hey Vemana

     

    Here is the test class of your code, fullfilly both the condition of method CheckDates:

    @isTest

    private class testClass {

    static testMethod void myUnitTest() {

    Test.startTest();

    date d1 = VerifyDate.CheckDates(Date.today(),Date.today().addDays(32));

    date d2 = VerifyDate.CheckDates(Date.today(),Date.today().addDays(2));

    Test.stopTest();

    }

    }

    Hope this is usefull to you.

     

    Thanks & Regards,

     

    Ajay Dubedi

     

     
0/9000