feat: test data and utils
This commit is contained in:
108
assignment/src/test/java/appointmentplanner/TestData.java
Normal file
108
assignment/src/test/java/appointmentplanner/TestData.java
Normal file
@@ -0,0 +1,108 @@
|
||||
package appointmentplanner;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
import appointmentplanner.api.AbstractAPFactory;
|
||||
import appointmentplanner.api.AppointmentData;
|
||||
import appointmentplanner.api.AppointmentRequest;
|
||||
import appointmentplanner.api.LocalDay;
|
||||
import appointmentplanner.api.LocalDayPlan;
|
||||
import appointmentplanner.api.TimePreference;
|
||||
import net.bytebuddy.asm.Advice.Local;
|
||||
|
||||
public interface TestData {
|
||||
|
||||
static final AbstractAPFactory FAC = ServiceFinder.getFactory();
|
||||
static final LocalDay TODAY = new LocalDay();
|
||||
|
||||
static final LocalTime T08_30 = LocalTime.of(8, 30);
|
||||
static final LocalTime T09_00 = LocalTime.of(9, 0);
|
||||
static final LocalTime T09_30 = LocalTime.of(9, 30);
|
||||
static final LocalTime T10_00 = LocalTime.of(10, 0);
|
||||
static final LocalTime T10_30 = LocalTime.of(10, 30);
|
||||
static final LocalTime T10_45 = LocalTime.of(10, 45);
|
||||
static final LocalTime T11_10 = LocalTime.of(11, 10);
|
||||
static final LocalTime T14_30 = LocalTime.of(14, 30);
|
||||
static final LocalTime T15_00 = LocalTime.of(15, 0);
|
||||
static final LocalTime T15_15 = LocalTime.of(15, 15);
|
||||
static final LocalTime T15_45 = LocalTime.of(15, 45);
|
||||
static final LocalTime T16_00 = LocalTime.of(16, 00);
|
||||
static final LocalTime T17_30 = LocalTime.of(17, 30);
|
||||
static final LocalTime WORKINGDAY_START = T08_30;
|
||||
static final LocalTime WORKINGDAY_END = T17_30;
|
||||
|
||||
static final Duration D15 = Duration.ofMinutes(15);
|
||||
static final Duration D30 = Duration.ofMinutes(30);
|
||||
static final Duration D80 = Duration.ofMinutes(80);
|
||||
static final Duration D90 = Duration.ofMinutes(90);
|
||||
static final Duration D200 = Duration.ofMinutes(200);
|
||||
|
||||
static final AppointmentData DATA1 = FAC.createAppointmentData("app1 30 min @9:00", D30);
|
||||
static final AppointmentData DATA2 = FAC.createAppointmentData("app2 30 min @9:30", D30);
|
||||
static final AppointmentData DATA3 = FAC.createAppointmentData("app3 15 min @10:30", D15);
|
||||
static final AppointmentData DATA4 = FAC.createAppointmentData("app4 15 min @10:45", D15);
|
||||
static final AppointmentData DATA5 = FAC.createAppointmentData("app5 200 min @11:10", D200);
|
||||
static final AppointmentData DATA6 = FAC.createAppointmentData("app6 30 min @14:30", D30);
|
||||
static final AppointmentData DATA7 = FAC.createAppointmentData("app7 90 min @16:00", D90);
|
||||
|
||||
static final AppointmentRequest AR1 = FAC.createAppointmentRequest(DATA1, T09_00, TimePreference.UNSPECIFIED);
|
||||
static final AppointmentRequest AR2 = FAC.createAppointmentRequest(DATA2, T09_30);
|
||||
static final AppointmentRequest AR3 = FAC.createAppointmentRequest(DATA3, T10_30);
|
||||
static final AppointmentRequest AR4 = FAC.createAppointmentRequest(DATA4, T10_45);
|
||||
static final AppointmentRequest AR5 = FAC.createAppointmentRequest(DATA5, T11_10);
|
||||
static final AppointmentRequest AR6 = FAC.createAppointmentRequest(DATA6, T14_30);
|
||||
static final AppointmentRequest AR7 = FAC.createAppointmentRequest(DATA7, T16_00, TimePreference.EARLIEST);
|
||||
|
||||
static LocalDayPlan standardDay() {
|
||||
LocalDayPlan td = emptyWorkingDay();
|
||||
addApps(td, AR1, AR2, AR3, AR4, AR5, AR6, AR7);
|
||||
return td;
|
||||
}
|
||||
|
||||
static LocalDayPlan emptyWorkingDay() {
|
||||
return emptyWorkingDay(WORKINGDAY_START);
|
||||
}
|
||||
|
||||
static LocalDayPlan emptyWorkingDay(LocalTime startTime) {
|
||||
return FAC.createLocalDayPlan(TODAY, startTime, WORKINGDAY_END);
|
||||
}
|
||||
|
||||
static LocalDayPlan addApps(LocalDayPlan dp, AppointmentRequest... app) {
|
||||
|
||||
for (AppointmentRequest ar : app) {
|
||||
dp.addAppointment(ar.appointmentData(), ar.startTime(), ar.timePreference());
|
||||
}
|
||||
return dp;
|
||||
}
|
||||
|
||||
static LocalDayPlan dayPlanFactory(String startTime, String endTime) {
|
||||
return FAC.createLocalDayPlan(TODAY, LocalTime.parse(startTime), LocalTime.parse(endTime));
|
||||
}
|
||||
|
||||
static LocalDayPlan dayPlanFactory(LocalDay day, String startTime, String endTime) {
|
||||
return FAC.createLocalDayPlan(day, LocalTime.parse(startTime), LocalTime.parse(endTime));
|
||||
}
|
||||
|
||||
static final AppointmentData APD1 = appointmentDataFactory(30, "Some app1");
|
||||
static final AppointmentData APD2 = appointmentDataFactory(30, "Some app2");
|
||||
static final AppointmentData APD3 = appointmentDataFactory(15, "Some app3");
|
||||
static final AppointmentData APD4 = appointmentDataFactory(15, "Some app4");
|
||||
static final AppointmentData APD5 = appointmentDataFactory(200, "Some app5");
|
||||
static final AppointmentData APD6 = appointmentDataFactory(30, "Some app6");
|
||||
static final AppointmentData APD7 = appointmentDataFactory(90, "Some app7");
|
||||
|
||||
static final Instant T13_10 = TODAY.at(13, 10);
|
||||
|
||||
static AppointmentData appointmentDataFactory(int duration, String someApp) {
|
||||
return FAC.createAppointmentData(someApp, Duration.ofMinutes(duration));
|
||||
}
|
||||
|
||||
static LocalDayPlan createStandardDay(LocalDate at) {
|
||||
LocalDay ld = new LocalDay(ZoneId.systemDefault(), at);
|
||||
return FAC.createLocalDayPlan(ld, ld.at(8, 30), ld.at(17, 30));
|
||||
}
|
||||
}
|
||||
10
assignment/src/test/java/appointmentplanner/TestUtils.java
Normal file
10
assignment/src/test/java/appointmentplanner/TestUtils.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package appointmentplanner;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
public static Duration makeDuration(String durationString) {
|
||||
return Duration.ofHours(Long.parseLong(durationString));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user