Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need the TODOs to be completed Complete ShoppingListArrayListTest.java by completing the testAdd(), testRemove(), and testFind() methods. Feel free to refer to the testIndexOf(), testContains(),

I need the TODOs to be completed

Complete ShoppingListArrayListTest.java by completing the testAdd(), testRemove(), and testFind() methods. Feel free to refer to the testIndexOf(), testContains(), testSize(), and testIsEmpty() methods.

/** * TODO To Complete the test of add method, of class ShoppingArray. */ @Test public void testAdd() { //Create grocery objects and a shopping list instance Grocery item1 = new Grocery("Harry Potter", "book", 3, 15.5f, 2); Grocery item2 = new Grocery(item1); item2.setQuantity(3); ShoppingListArrayList instance = new ShoppingListArrayList();

// TODO test the add method for the case of adding a new item (item1) into list instance // Be sure that 1) size is increased by 1 and // 2) the first item in the list // is the same as in the reference variable, item1

// TODO test the "combine" feature of the add method // for the case of adding an existing entry, the item2 // into the shopping list instance created in previous // code block. The item2 has the same entry name as the item1. // Be sure that 1) size is not changed and 2) quantities are // properly changed in the first item in the list.

// Test adding a null entry reference to the shpping list instance.add(null); assertTrue(1 == instance.size()); // Test creating and adding a new grocery object to the list // Be sure that 1) the shopping list has a proper number of items // 2)the list item in the list // is the same as in the newly created grocery object Grocery item3 = new Grocery("Laugh in the Rains", "book", 3, 35.5f, 1); instance.add(item3); System.out.println("Test..." + instance.size()); assertTrue(2 == instance.size()); try{ assertTrue(item3.compareTo(instance.find(1)) == 0); assertTrue(1 == item3.getQuantity()); assertTrue(1 == instance.find(1).getQuantity()); } catch (Exception ex){ ex.printStackTrace(); } }

/** * TODO To Complete the test of remove method, of class ShoppingArrayList. */ @Test public void testRemove() { //Create grocery objects Grocery item1 = new Grocery("Harry Potter", "book", 3, 15.5f, 2); Grocery item2 = new Grocery("Hunger Game", "book", 3, 10.5f, 3); // Construct a shopping list ShoppingListArrayList instance = new ShoppingListArrayList(); instance.add(item1); instance.add(item2); assertTrue(2 == instance.size()); boolean isRemoved; // TODO test the remove method for an existing entry // Be sure that // 1) the returned value from the remove method is true // 2) the shopping list is decreased by 1 // 3) the item being removed can not be found in the shopping list

// TODO test the remove method for a non-existing entry // Be sure that // 1) the returned value from the remove method is false // 2) the shopping list is not changed

/** * TODO To Complete the test of find method, of class ShoppingArrayList. */ @Test public void testFind() { //Create grocery objects Grocery item1 = new Grocery("Harry Potter", "book", 3, 15.5f, 2); Grocery item2 = new Grocery("Hunger Game", "book", 3, 10.5f, 3); // Construct a shopping list ShoppingListArrayList instance = new ShoppingListArrayList(); // TODO Test the case of finding a grocery object when the shopping list is empty // Be sure that // An EmptyCollectionException instance is thrown in the case

// Add item1 into the shopping list instance.add(item1); instance.add(item2); assertTrue(2 == instance.size()); // TODO Test the case of finding a grocery object which index is larger than the shopping list size // Be sure that // An IndexOutOfBoundsException instance is thrown in the case

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago