concept Passenger in category java

appears as: Passenger, Passenger
JUnit in Action

This is an excerpt from Manning's book JUnit in Action.

One project under development at Tested Data Systems is a flight-management application. The application creates and sets up flights; it also adds and removes passengers. The engineers want to test the integration between two classes: Passenger and Flight. The test will check whether each passenger can be added to or removed from a flight correctly, as well as whether the number of passengers exceeds the number of seats. (Nobody wants to get on a flight without having a seat!) The following two listings show the Passenger and Flight classes, as well as their logic.

We’ll start by demonstrating the traditional approach, where dependencies need to be managed by the developer at the level of the code. You will find the first examples in the ch16-traditional folder from the source code of this chapter. In our example flight-management application developed at Tested Data Systems, each passenger who is tracked comes from a country. In figure 16.2, a Passenger object is dependent on a Country object. We initialize this dependency directly in listings 16.1 and 16.2.

Figure 16.2 A passenger is from a country, and the Passenger object is dependent on a Country object.
Listing 16.2 Passenger class
public class Passenger {
    private String name;                                                #1
    private Country country;                                            #2
 
    public Passenger(String name) {                                     #3
        this.name = name;                                               #3
        this.country = new Country("USA", "US");                        #3
    }                                                                   #3
 
    public String getName() {                                           #1
        return name;                                                    #1
    }                                                                   #1
 
    public Country getCountry() {                                       #2
        return country;                                                 #2
    }                                                                   #2
 
}
  • Passenger and Country are not dependent and do not depend on any outer libraries—they are POJOs.