Skip to main content
Sara Monksfield (RSC) ha preguntado en #Apex
Hi, I'm getting the same error on all the code I try for  the Trailhead Challenge 'Create a unit test for a simple Apex Class'.

The error I get is: Method does not exist or incorrect signature: void CheckDates(Date, Date) from the type VerifyDate

I have tried the following:

@isTest

private class TestVerifyDate {

    

    static testMethod void TestVerifyDates() {

        VerifyDate.CheckDates(system.today(),system.today().addDays(10));

        

        VerifyDate.CheckDates(system.today(),system.today().addDays(78));

       

    }

}

Also:

@isTest

public class TestVerifyDate {

    @isTest static void testVerifyDate(){

        date date1=VerifyDate.CheckDates(system.today(),system.today().addDays(10));

        System.assertEquals(system.today().addDays(10),date1);

        

        date date2=VerifyDate.CheckDates(system.today(),system.today().addDays(78));

        System.assertEquals(system.today(),date2);

    }

}

Also:

@isTest

private class TestVerifyDate{

    @isTest static void testDt1GtrDt2(){

        Date d2 = system.today();

        Date d1 = d2.addDays(10);

        

        Date dt = VerifyDate.CheckDates(d1, d2);

        Date testDt = Date.newInstance(2017, 7, 31);

        System.assertEquals(dt, testDt);

    }

    

    @isTest static void testDt2Within30dayOfDt1(){

        Date d1 = system.today();

        Date d2 = d1.addDays(10);

        

        Date dt = VerifyDate.CheckDates(d1, d2);

        System.assertEquals(dt, d2);

    }

}

This is the code for the Class itself:

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) {

//check for date2 being in the past

if( date2 < date1) { return false; }

//check that date2 is within (>=) 30 days of date1

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;

}

}

Can anyone point me to what I am doing wrong please?

Thanks!

 
3 respuestas
  1. 21 ago 2018, 7:27
    Thanks everyone. Weirdly when I checked the challenge it passed so there was clearly some kind of glitch.  This is one of the reasons I find Trailhead a bit difficult!
0/9000