Create a second test class called TicketTest to test that a Ticket object isconstructed correctly when provided reasonable input.a. Write a test method that calls the following constructor with valid arguments:Ticket(Passenger p, Seat s, double price)Before you create the Ticket object:i. Use the wizard to generate the TicketTest classii. Add a test method to the class.iii. In the test method, create a Passenger object. The default constructorof the Passenger class generates a valid name “T. B. A.”, so either ofthe following statements instantiate a Passenger:Passenger passenger = new Passenger();Or:Passenger passenger = new Passenger(new PassengerName(“Mary”, “I”, “Worth”));iv. Create a Seat object.The Seat class has no explicit constructor so you must use the implicitdefault constructor and then call seat.setRow(int i) andseat.setLetter(char c) to specify a specific seat.Unit Testing with JUnitv. Create the ticket object, providing the passenger object, seat object and the price as a number as the three arguments of the constructor.Ticket ticket = new Ticket(passenger, seat, price);b. For a condition that verifies that a ticket is issued, use the fact that tickets are numbered, starting at 1,000,000. So lines in the test method could look like:assertTrue(ticket.getTicketNo() > 1000000 );c. Write a second test in the same class that generates a ticket when called with arguments that are not valid. In real life, you should create several tests to isolate different combinations of valid and invalid input values, but for purposes of this exercise combine several tests, as in:@Testpublic void testTicketBad() {assertThrows(IllegalArgumentException.class, ()->{Ticket ticket = new Ticket(null, null, -100.0);} );}d. Run the test class as a JUnit test and take note of the results.Hint: The test fails because the second test method does not throw an exception where clearly one should be thrown. This defect should be reported. It would helpful for the test report suggest more tests that give better coverage invalid input.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here