不能从非静态上下文引用静态方法:Date-dateHolidayHandler.isdaybusinessday(Dat



大家好,这是我的类中的一个方法,当我从测试类调用时,我收到了与静态方法相关的错误。不能从非静态上下文引用该方法

public static date adddayswithholidays(date indate,integer noofdays,boolean reverse){ 
//Create a set for the holiday dates
set<date> holidayset = new set<date>();
boolean bstop = false;

//Get the holiday dates
If (!bholidayrun){
holidaylist=[select activitydate from holiday];
bholidayrun =true;
}

//Setup the holiday set
If (holidaylist !=null){
for (holiday h:holidaylist){
holidayset.add(h.activitydate);
}
} 
for(Integer i=0;i < noofdays;i++){
//If this date is in the holiday list
//Add a day. Repeat until not a holiday.
bstop =false;
If(holidayset !=null){
while(bstop ==false){
if(holidayset.contains(indate)){
//Add a day
indate = indate.adddays(1);
}else{
bstop = true;
}
}
}
//Add the next day to the indate
If(reverse){
indate =indate.adddays(-1);
}else{
indate =indate.adddays(1);
}

Datetime dt = datetime.newInstance(indate.year(), indate.month(),indate.day());
String weekday = dt.format('E'); 

if (weekday == 'Sat'){
system.debug('found a saturday' + indate);
If(reverse){
indate =indate.adddays(-1);
}else{
indate =indate.adddays(2);
}
}
if (weekday =='Sun'){
system.debug('found a sunday' + indate);
If(reverse){
indate =indate.adddays(-2);
}else{
indate =indate.adddays(1);
}
}

//Check for holidays again before sending back
bstop =false;
If(holidayset !=null){
while(bstop ==false){
if(holidayset.contains(indate)){
//Add a day
If(reverse){
indate =indate.adddays(-1);
}else{
indate =indate.adddays(1);
}

}else{
bstop = true;
}
}
}
}
return indate;
}

//这是我如何得到错误的测试类

//问题1:每当我调用时,我都会得到错误。静态方法不能从非静态上下文中引用

@isTest static void UnitTest1(){

dateHolidayHandler d=新日期HolidayHandler((;布尔bholidayrun=true;

date indate=Date.today().addDays(1);
date td1=Date.today().addDays(-2);
Holiday h=new Holiday();
h.name='test';
h.ActivityDate=date.today();
insert h;
system.assertEquals(system.today(), h.ActivityDate);
d.adddayswithholidays(indate, 1, true);
d.isdaybusinessday(td1, true);

}

错误告诉您停止执行

dateHolidayHandler d=new dateHolidayHandler();
// ...
d.adddayswithholidays(indate, 1, true);
d.isdaybusinessday(td1, true);

你的方法是静态的,所以它不需要实例,也不需要"新的";。

称之为DateHolidayHandler.adddayswithholidays(indate, 1, true);

相关内容

  • 没有找到相关文章

最新更新