JenkinsSonaImron
3 years ago
3 changed files with 108 additions and 0 deletions
-
42src/main/java/hs/fulda/de/ci/exam/project/FrontDeskOfficer.java
-
13src/main/java/hs/fulda/de/ci/exam/project/Itinerary.java
-
53src/test/java/hs/fulda/de/ci/exam/project/FrontDeskOfficerTest.java
@ -0,0 +1,42 @@ |
|||
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(); |
|||
itinerary.validateCreationDate(); |
|||
} |
|||
} |
@ -0,0 +1,53 @@ |
|||
package hs.fulda.de.ci.exam.project; |
|||
|
|||
import org.junit.Before; |
|||
import org.junit.jupiter.api.*; |
|||
import org.mockito.InjectMocks; |
|||
|
|||
import java.util.Date; |
|||
|
|||
import static org.junit.jupiter.api.Assertions.*; |
|||
|
|||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) |
|||
public class FrontDeskOfficerTest { |
|||
|
|||
Address address1; |
|||
Airport airport_fr; |
|||
Airport airport_be; |
|||
FrontDeskOfficer frontDeskOfficer; |
|||
|
|||
@BeforeAll |
|||
public void setupAll(){ |
|||
System.out.println("Should Print Before All Tests"); |
|||
} |
|||
@BeforeEach |
|||
public void setup(){ |
|||
address1 = new Address("Fuldaer str", "Fulda", "Hessen", "36037", "Germany"); |
|||
airport_fr = new Airport("Fraport", address1, "1234"); |
|||
airport_be = new Airport("Berlin", address1, "5678"); |
|||
frontDeskOfficer = new FrontDeskOfficer("John", address1, "example@email.com", "0151238967"); |
|||
} |
|||
@Test |
|||
public void shouldCreateItinerary() { |
|||
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()); |
|||
} |
|||
@Test |
|||
@DisplayName("Should Not Create Itinerary when Starting Airport is null") |
|||
public void shouldThrowRuntimeExceptionWhenStartAirportIsNull(){ |
|||
assertThrows(RuntimeException.class, () -> { |
|||
frontDeskOfficer.createItinerary(null, airport_be, new Date()); |
|||
}); |
|||
} |
|||
|
|||
@Test |
|||
@DisplayName("Should Not Create Itinerary when Destination Airport is null") |
|||
public void shouldThrowRuntimeExceptionWhenFinalAirportIsNull(){ |
|||
assertThrows(RuntimeException.class, () -> { |
|||
frontDeskOfficer.createItinerary(airport_fr, airport_be, null); |
|||
}); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue