Question: Hello, I need to write code that will test the junit test in the photo. I was givin these hints : Harbor Before you continue,

Hello, I need to write code that will test the junit test in the photo.
I was givin these hints :
Harbor
Before you continue, go ahead and visit the style guide from the module. Comment your Boat class per the required style.
The Harbor class will be a class that has-many Boat objects. This means you should be using a data structure (Arrays!).
Constructor
A Harbor is created with a parameter that corresponds to the number of spots for Boats. Hint: The size of your array.
getBoatAt
This method should return the boat at the given index, null if that spot is empty.
parkBoatAt
This method will set the position in the array, but if there is a Boat at the given position, return that object. Otherwise, it returns null.
getInventory
Return a copy of the inventory. Hint: This is not just a getter/accessor for the one-dimensional array of Boat objects! Make sure to write your own code to create the copy; do not use the Arrays class or a clone method.
For the remainder of the classes, see if you can figure out the logic based on the tester.
Hints: You will have to override the toString method multiple times in this programming assignment. Make sure you include required white spaces!
@Test
void testHarbor()
{
// A harbor has many boats
Boat boat1= new Boat ("BMC", Color. GREEN);
Boat boat2= new Boat ("BMX", Color. RED );
Boat boat3= new Boat ("UXB", Color. YELLOW);
Harbor stock = new Harbor (5);
assertEquals (null, stock.getBoatAt (0));
assertEquals (null, stock.getBoatAt (1));
assertEquals (null, stock.getBoatAt (2));
assertEquals (null, stock.getBoatAt (3));
assertEquals (null, stock.getBoatAt (4));
// Hint: parkBoatAt is not just an accessor, and not just a mutator
assertEquals (null, stock.parkBoatAt (boat1,3));
Boat retrievedBoat = stock.parkBoatAt (boat2,3);
assertEquals (boat1, retrievedBoat);
retrievedBoat = stock.parkBoatAt (boat3,3);
assertEquals (boat2, retrievedBoat);
Boat[] inventory = stock.getInventory ();
assertArrayEquals (new Boat []{null, null, null, boat3, null}, inventory);
stock.parkBoatAt (boat2,1);
// The inventory is a carbon copy list of boats that is handed out to interested parties.
assertArrayEquals (new Boat []{null, null, null, boat3, null}, inventory); // This is correct!
assertArrayEquals (new Boat []{null, boat2, null, boat3, null}, stock.getInventory());
}
 Hello, I need to write code that will test the junit

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!