Question: Class TrainTest import java.util.ArrayList; /** * The test class TrainTest. * * @author Lynn Marshall * @version May 2015 */ public class TrainTest extends junit.framework.TestCase

Class TrainTest
import java.util.ArrayList;
/** * The test class TrainTest. * * @author Lynn Marshall * @version May 2015 */ public class TrainTest extends junit.framework.TestCase { /** * Default constructor for test class TrainTest */ public TrainTest() { }
/** * Sets up the test fixture. * * Called before every test case method. */ protected void setUp() { }
/** * Tears down the test fixture. * * Called after every test case method. */ protected void tearDown() { } public void testCreateEmptyTrain() { Train aTrain = new Train(); /* Verify that a new train has no cars. */ assertEquals(0, aTrain.cars().size()); } public void testAddCar() { Train aTrain = new Train(); Car car1 = new Car(1250, true); aTrain.addCar(car1); Car car2 = new Car(1300, false); aTrain.addCar(car2); Car car3 = new Car(1740, false); aTrain.addCar(car3); ArrayList
Class Train
import java.util.ArrayList;
public class Train { /** The cars in this train. */ private ArrayList
4. Add a new test method testBookCancelTicket which is to be used to check that we can properly book a ticket after it has been cancelled Ensure that vou avoid using a boolean "result". o Create a train with four cars (two business and two economy) as in the previous methods As in testCancelTicket fill the seats in the first business car and half the second business car, but just one of the economy cars o o Cancel any three tickets in the economy car. o Book four economy tickets and check that you get each of the three cancelled (starting with the one nearest the front of the car), and then, for the fourth, the first seat in the second economy car Cancel three business car tickets: one in the first business car and two near the front of the second. o o Book four business tickets and check that you get each of the three cancelled (starting with the one in the first business car), and then, for the fourth, seat 16 of the second business car. o Ensure that you avoided using a boolean "result". 5. You should have noticed by now that the first part most methods is identical Move the repetitive code to TrainTest's constructor. Note that you will need to add five fields: aTrain (type Train) and carl, car2, car3, and car4 (type Car) The TrainTest constructor will create the train and the four cars, and add the four cars to the train. o Method testCreateEmptyTrain is unchanged, although renaming the Train object to emptyTrain makes the code a little clearer. The other methods can now be shortened o o 4. Add a new test method testBookCancelTicket which is to be used to check that we can properly book a ticket after it has been cancelled Ensure that vou avoid using a boolean "result". o Create a train with four cars (two business and two economy) as in the previous methods As in testCancelTicket fill the seats in the first business car and half the second business car, but just one of the economy cars o o Cancel any three tickets in the economy car. o Book four economy tickets and check that you get each of the three cancelled (starting with the one nearest the front of the car), and then, for the fourth, the first seat in the second economy car Cancel three business car tickets: one in the first business car and two near the front of the second. o o Book four business tickets and check that you get each of the three cancelled (starting with the one in the first business car), and then, for the fourth, seat 16 of the second business car. o Ensure that you avoided using a boolean "result". 5. You should have noticed by now that the first part most methods is identical Move the repetitive code to TrainTest's constructor. Note that you will need to add five fields: aTrain (type Train) and carl, car2, car3, and car4 (type Car) The TrainTest constructor will create the train and the four cars, and add the four cars to the train. o Method testCreateEmptyTrain is unchanged, although renaming the Train object to emptyTrain makes the code a little clearer. The other methods can now be shortened o o
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
