Browse Source

create Itinerary method testing

feature-pr-FrontDeskOfficer
Sona Markosyan 3 years ago
parent
commit
0c42867e75
  1. 41
      src/main/java/hs/fulda/de/ci/exam/project/FrontDeskOfficer.java
  2. 9
      src/main/java/hs/fulda/de/ci/exam/project/Itinerary.java
  3. 26
      src/test/java/hs/fulda/de/ci/exam/project/FrontDeskOfficerTest.java

41
src/main/java/hs/fulda/de/ci/exam/project/FrontDeskOfficer.java

@ -0,0 +1,41 @@
package hs.fulda.de.ci.exam.project;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class FrontDeskOfficer extends Person{
Map<String, Itinerary> itineraryList = new ConcurrentHashMap<String, Itinerary>();
public FrontDeskOfficer(String name, Address address, String email, String phone) {
super(name, address, email, phone);
}
public void createItinerary(Airport start_airport, Airport final_airport, Date date){
Itinerary itinerary = new Itinerary(start_airport, final_airport, date);
validateItinerary(itinerary);
checkIfItineraryAlreadyExist(itinerary);
itineraryList.put(generateKey(itinerary), itinerary);
}
public Collection<Itinerary> getAllItineraries() {
return itineraryList.values();
}
private void checkIfItineraryAlreadyExist(Itinerary itinerary){
if(itineraryList.containsKey(generateKey(itinerary))){
throw new RuntimeException("Itinerary Already Exists");
}
}
private String generateKey(Itinerary itinerary) {
return String.format("%s-%s", itinerary.getStart_airport(), itinerary.getFinal_airport());
}
public void validateItinerary(Itinerary itinerary){
itinerary.validateStartAirport();
itinerary.validateFinalAirport();
}
}

9
src/main/java/hs/fulda/de/ci/exam/project/Itinerary.java

@ -73,5 +73,14 @@ public class Itinerary {
this.start_airport = start_airport;
}
public void validateStartAirport() {
if(this.start_airport.getName().isBlank())
throw new RuntimeException(("Starting Airport Cannot be null or empty"));
}
public void validateFinalAirport() {
if(this.final_airport.getName().isBlank())
throw new RuntimeException(("Destination Airport Cannot be null or empty"));
}
}

26
src/test/java/hs/fulda/de/ci/exam/project/FrontDeskOfficerTest.java

@ -0,0 +1,26 @@
package hs.fulda.de.ci.exam.project;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import java.util.Date;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class FrontDeskOfficerTest {
@Test
public void shouldCreateItinerary() {
final Address address1 = new Address("Fuldaer str", "Fulda", "Hessen", "36037", "Germany");
final Airport airport_fr = new Airport("Fraport", address1, "1234");
final Airport airport_be = new Airport("Berlin", address1, "5678");
FrontDeskOfficer frontDeskOfficer = new FrontDeskOfficer("John", address1, "example@email.com", "0151238967");
frontDeskOfficer.createItinerary(airport_fr, airport_be, new Date());
assertFalse(frontDeskOfficer.getAllItineraries().isEmpty());
assertEquals(1, frontDeskOfficer.getAllItineraries().size());
assertTrue(frontDeskOfficer.getAllItineraries().stream().filter(itinerary -> itinerary.getStart_airport().equals(airport_fr) &&
itinerary.getFinal_airport().equals(airport_be)).findAny().isPresent());
}
}
Loading…
Cancel
Save