我有如下代码
ScheExeService.ScheduleId scheduleID = ScheExeService.getOneTimeScheduleId(nl.getCompany(), workItem.getId());
ScheExeService.Schedule schedule = ScheExeService.loadSchedule(nl, scheduleID.getId());
Calendar cal = Calendar.getInstance(java.util.TimeZone.getTimeZone(nl.getTimeZone()));
cal.setTime(schedule.attributes.startDate.toDate());
而且我正在尝试模拟“schedule.attributes.startDate.toDate()”
和 ScheExeService 如下所示
public class ScheExeService implements blah
{
public final static class Schedule {
public final ScheduleId id;
public final ScheduleAttributes attributes;
public final String callableClassName;
public final long itemId;
public Schedule(ScheduleId id, ScheduleAttributes attributes, String callableClassName, long itemId)
{
this.id = id;
this.attributes = attributes;
this.callableClassName = callableClassName;
this.itemId = itemId;
}
}
public final static class ScheduleAttributes {
public final @Nullable LocalDate startDate;
public final @Nullable LocalTime startTime;
public final @Nullable LocalDate endDate;
public final @Nullable LocalTime endTime;
Method code
}
}
我试过了
doNothing().doThrow(new RuntimeException()).when(mockedCalenderObject).setTime(null);
但我不断得到NPE。
我怎样才能避免 schedule.attributes.startDate.todate() 调用..?