Test Driven Development with JUnit 5. Part 2

2. The flight-management application

  • The Passenger class contains a name field #1 together with a getter for it #4
  • It also contains a VIP field #2 together with a getter for it #5
  • The constructor of the Passenger class initializes the name and VIP fields #3
  • The Flight class contains an identifier #1 together with a getter for it #5, a list of passengers initialized as an empty list #2 together with a getter for it #6, and a flight type #3 together with a getter for it #7.
  • The constructor of the Flight class initializes the id and the flightType fields #4.
  • The addPassenger method checks the flight type #8. If it is an economy flight, any passengers can be added #9. If it is a business flight, only VIP passengers can be added #10. Otherwise (if the flight is neither an economy nor a business flight), the method will throw an exception, as it cannot handle an unknown flight type #11.
  • The removePassenger method checks the flight type #12. If it is an economy flight, only regular passengers can be removed #13. If it is a business flight, passengers cannot be removed #14. Otherwise (if the flight is neither an economy nor a business flight), the method will throw an exception, as it cannot handle an unknown flight type #15.
  • We initialize an economy flight and a business flight #1. We also initialize James as a VIP passenger and Mike as a regular passenger #2.
  • We try to add James to and remove him from the business flight #3, and then we try to add Mike to and remove him from the business flight #4 and the economy flight #5.
  • We print the list of passengers on the business flight #6 and the economy flight #7.

https://www.luxoft-training.com/

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Your Author Website’s Administrator: Should It Be You?

SST: The Most Underrated Serverless Framework You Need to Discover

How to Choose the Right Type of Database for your Enterprise? — Aalpha

A Simple Way to Print Out iPhone Text Messages Without Using 3rd Party Apps

VERSION CONTROL WITH GIT FOR BEGINNERS

Sneak peek into KSQL-DB : Confluent Kafka Platform | Part1

NEED OF DIFFERENT SORTING TECHNIQUES

Get your open source house in order

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Luxoft Training

Luxoft Training

https://www.luxoft-training.com/

More from Medium

Dependency Injection in Spring

Introduction to Maven ,Spring Framework and Spring Boot

Spring Boot Embedded Tomcat getNextJarEntry