diff --git a/pom.xml b/pom.xml
index 5d85a1b..b1ad7be 100644
--- a/pom.xml
+++ b/pom.xml
@@ -123,6 +123,15 @@
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ true
+
+
diff --git a/src/main/java/de/etecture/ga/service/AppointmentService.java b/src/main/java/de/etecture/ga/service/AppointmentService.java
index 83a0760..beda030 100644
--- a/src/main/java/de/etecture/ga/service/AppointmentService.java
+++ b/src/main/java/de/etecture/ga/service/AppointmentService.java
@@ -107,19 +107,14 @@ public class AppointmentService {
Assert.notNull(from, "from must be not null");
Assert.notNull(till, "till must be not null");
- Optional garage = garageService.getGarage(garageId);
- if (garage.isEmpty())
- throw new IllegalArgumentException("GarageId not valid");
+ Garage garage = garageService.getGarage(garageId)
+ .orElseThrow(() -> new IllegalArgumentException("GarageId not valid"));
+ GarageServices garageService = garage.garageServices().stream()
+ .filter(gs -> serviceId == gs.serviceId().getId()).findFirst()
+ .orElseThrow(() -> new IllegalArgumentException("serviceId not valid"));
- Optional garageService = garage.get().garageServices().stream()
- .filter(gs -> serviceId == gs.serviceId().getId()).findFirst();
- if (garageService.isEmpty())
- throw new IllegalArgumentException("serviceId not valid");
-
- return getValidAppointmentTimeList(garage.get(), garageService.get(), from, till).stream()
- .map(t -> new Appointment().serviceId(AggregateReference.to(serviceId))
- .appointmentTime(DateTimeUtil.toDate(t)))
- .toList();
+ return getValidAppointmentTimeList(garage, garageService, from, till).stream().map(t -> new Appointment()
+ .serviceId(AggregateReference.to(serviceId)).appointmentTime(DateTimeUtil.toDate(t))).toList();
}
/**
@@ -141,19 +136,17 @@ public class AppointmentService {
Assert.notNull(from, "from must be not null");
Assert.notNull(till, "till must be not null");
- Optional garage = garageService.getGarage(garageId);
- if (garage.isEmpty())
- throw new IllegalArgumentException("GarageId not valid");
-
- Optional service = serviceService.getMDService(serviceId)
- .filter(s -> garage.get().garageServices().stream().anyMatch(gs -> s.id() == gs.serviceId().getId()));
- Optional garageServices = garage.get().garageServices().stream()
- .filter(gs -> serviceId == gs.serviceId().getId()).findFirst();
- if (service.isEmpty() || garageServices.isEmpty())
- throw new IllegalArgumentException("serviceId not valid");
+ Garage garage = garageService.getGarage(garageId)
+ .orElseThrow(() -> new IllegalArgumentException("GarageId not valid"));
+ MDService service = serviceService.getMDService(serviceId)
+ .filter(s -> garage.garageServices().stream().anyMatch(gs -> s.id() == gs.serviceId().getId()))
+ .orElseThrow(() -> new IllegalArgumentException("serviceId not valid"));
+ GarageServices garageServices = garage.garageServices().stream()
+ .filter(gs -> serviceId == gs.serviceId().getId()).findFirst()
+ .orElseThrow(() -> new IllegalArgumentException("serviceId not valid"));
// check appointment times
- LocalDateTime validAppointmentTime = getValidAppointmentTime(garage.get(), garageServices.get(), from, till);
+ LocalDateTime validAppointmentTime = getValidAppointmentTime(garage, garageServices, from, till);
// create appointment
if (validAppointmentTime != null) {
@@ -206,13 +199,13 @@ public class AppointmentService {
return appointments < garage.maxAppointments();
}
- private Appointment createAppointmentObj(Optional garage, Optional service,
- Optional garageService, LocalDateTime validAppointmentTime) {
+ private Appointment createAppointmentObj(Garage garage, MDService service, GarageServices garageService,
+ LocalDateTime validAppointmentTime) {
- Appointment appointment = new Appointment().garageId(AggregateReference.to(garage.get().id()))
+ Appointment appointment = new Appointment().garageId(AggregateReference.to(garage.id()))
.appointmentTime(DateTimeUtil.toDate(validAppointmentTime))
- .serviceId(AggregateReference.to(service.get().id())).serviceCode(service.get().code())
- .serviceName(service.get().name()).duration(garageService.get().duration());
+ .serviceId(AggregateReference.to(service.id())).serviceCode(service.code()).serviceName(service.name())
+ .duration(garageService.duration());
return appointment;
}
}
diff --git a/src/test/java/de/etecture/ga/GarageAppointmentAppTests.java b/src/test/java/de/etecture/ga/GarageAppointmentAppTests.java
index 19fc944..cbe0e72 100644
--- a/src/test/java/de/etecture/ga/GarageAppointmentAppTests.java
+++ b/src/test/java/de/etecture/ga/GarageAppointmentAppTests.java
@@ -29,10 +29,9 @@ class GarageAppointmentAppTests {
Optional testGarage = garageRepository.findByCode("test-data");
-
assertNotNull(testGarage.get(), "Garage should not be null");
assertEquals("Test Autohaus", testGarage.get().name());
- assertTrue(testGarage.get().appointments().size() == 19, "Test Autohaus should have 19 appointments");
+ assertTrue(testGarage.get().appointments().size() == 18, "Test Autohaus should have 19 appointments");
assertTrue(testGarage.get().garageServices().size() == 3, "Test Autohaus should have 3 services");
}