train-reservation issueshttps://univ-nantes.io/naomod/testing/testing-resources/train-reservation/-/issues2021-09-28T14:38:17Zhttps://univ-nantes.io/naomod/testing/testing-resources/train-reservation/-/issues/3TripException isn't thrown in createTrip2021-09-28T14:38:17ZMathieu FéryTripException isn't thrown in createTripSelon l'interface `fr.univnantes.trainreservation.TicketReservationSystem` la methode `createTrip()` doit respecter la signature et le fonctionnement suivant :
```java
/**
* Creates and registers a new trip in the system.
*...Selon l'interface `fr.univnantes.trainreservation.TicketReservationSystem` la methode `createTrip()` doit respecter la signature et le fonctionnement suivant :
```java
/**
* Creates and registers a new trip in the system.
* This new trip must take place *after* the last trip of the chosen train (based on the real arrival time).
* In addition, a trip can only be created if the following constraints are satisfied:
* - The last destination of the train must be in the same city as the origin of the new trip.
* - The last arrival of the train must be at least 10 minutes from the departure of the new trip (using real departure and arrival times).
* - The arrival must come after the departure.
* - The origin must be different from the destination.
* @return The created registered trip.
* @throws TripException If one of the above constraints was not satisfied.
*/
Trip createTrip(City origin, City destination, Train train, Instant departure, Instant arrival) throws TripException;
```
Hors dans l'implementation `fr.univnantes.trainreservation.impl.TicketReservationSystemImpl` on constate que les conditions d'invalidités du trajet ne sont vérifiées que si le train spécifié pour le nouveau trajet a au moins un trajet renseigné. Ainsi des conditions sans rapport avec les trajets antérieurs du train ne sont pas vérifiées on peux donner en exemple les conditions suivantes :
- L'heure d'arrivée doit être après l'heure de départ
- La ville d'origine doit être différente de la ville de destination.
On pourrait donc corriger cela de deux manières :
- Soit en altérant la spécification de cette façon par exemple :
```java
/**
* Creates and registers a new trip in the system.
* This new trip must take place *after* the last trip of the chosen train (based on the real arrival time).
* In addition, a trip can only be created:
* - If the following constraints are satisfied :
* - The last destination of the train must be in the same city as the origin of the new trip.
* - The last arrival of the train must be at least 10 minutes from the departure of the new trip (using real departure and arrival times).
* - The arrival must come after the departure.
* - The origin must be different from the destination.
* - Or if this trip is first trip of given train.
* @return The created registered trip.
* @throws TripException If one of the above constraints was not satisfied.
*/
Trip createTrip(City origin, City destination, Train train, Instant departure, Instant arrival) throws TripException;
```
- Soit en altérant l'implémentation, en vérifiant les conditions qui n'ont pas besoin des anciens trajet du train associé même si celui-ci n'a pas de trajet. En ce basant sur l'implementation actuelle on pourrait la modifier de cette façon par exemple :
```java
@Override
public Trip createTrip(City origin, City destination, Train train, Instant departure, Instant arrival) throws TripException {
List<Trip> trainTrips = this.findOrderedTripsOfTrain(train);
boolean durationTripIsValid = arrival.isAfter(departure);
boolean originIsDifferentFromDestination = origin != destination;
if (!(durationTripIsValid && originIsDifferentFromDestination))
throw new TripException();
if (!trainTrips.isEmpty()) {
Trip lastTrainTrip = trainTrips.get(trainTrips.size() - 1);
boolean comesAfter = lastTrainTrip.findRealArrivalTime().isBefore(departure);
boolean c1 = lastTrainTrip.getDestination() == origin;
boolean c2 = Duration.between(lastTrainTrip.findRealArrivalTime(), departure)
.compareTo(Duration.ofMinutes(10)) == 1;
if (!(comesAfter && c1 && c2))
throw new TripException();
}
Trip trip = new TripImpl(origin, destination, train, departure, arrival);
trips.add(trip);
return trip;
}
```
P.S. : Désolé par avance pour la mise en page, gitlab depuis mobile ce n'est pas l'idéal.https://univ-nantes.io/naomod/testing/testing-resources/train-reservation/-/issues/2Provide a more complete README with some examples of API usage2021-03-12T08:15:42ZErwan BOUSSEProvide a more complete README with some examples of API usagehttps://univ-nantes.io/naomod/testing/testing-resources/train-reservation/-/issues/1Improve the management and propagation of "cancel"2021-03-12T08:15:23ZErwan BOUSSEImprove the management and propagation of "cancel"