assenger p, Seat s, double price) Before you create the Ticket object: i. Use the wizard to generate the TicketTest class ii. Add a test method to the class. iii. In the test method, create a Passenger object. The default constructor of the Passenger class

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Create a second test class called TicketTest to test that a Ticket object is
constructed 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 class
ii. Add a test method to the class.
iii. In the test method, create a Passenger object. The default constructor
of the Passenger class generates a valid name “T. B. A.”, so either of
the 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 implicit
default constructor and then call seat.setRow(int i) and
seat.setLetter(char c) to specify a specific seat.
Unit Testing with JUnit

v. 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:
@Test
public 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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 7 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY