Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1.Complete ShoppingListArrayListTest.java by completing the testAdd(), testRemove(), and testFind() methods. Feel free to refer to the testIndexOf(), testContains(), testSize(), and testIsEmpty() methods for examples of
1.Complete ShoppingListArrayListTest.java by completing the testAdd(), testRemove(), and testFind() methods. Feel free to refer to the testIndexOf(), testContains(), testSize(), and testIsEmpty() methods for examples of how to test elements of this project. PLEASE HELP
aTest public void testRemove() \{ //Create grocery objects Grocery iteml = new Grocery("Harry Potter", "book", 3,15.5f,2); Grocery item2 = new Grocery ("Hunger Game", "book", 3,10.5f,3); // Construct a shopping list instance = new Shoppingtistarraytist(); instance.add(iteml); instance.add(item2); assertequals(2, instance.size()); boolean isRemoved; // Todo test the remove method for an existing entry, iteml // 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 cannot 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 // Construct a case that the shopping list becomes empty isRemoved = instance. remove (item2); assertTrue (isRemoved); assertEquals (0, instance.size ()); // Test the remove method when the shopping list is empty isRemoved = instance.remove (item2); assertFalse (isRemoved); assertEquals (0, instance.size ()); \} @Test public void testIndexOf() \{ //Create grocery objects Grocery iteml = new Grocery ("Harry Potter", "book", 3, 15.5f, 2); Grocery item2 = new Grocery("Hunger Game", "book", 3, 10.5f, 3); // Construct an empty shopping list instance = new ShoppingListarrayList () ; // Check the indexof method when the shopping list is empty try \{ int index = instance. indexof (iteml); \} catch (Exception e) \{ assertTrue (e instanceof ElementNotFoundException); \} // Add grocery items into the shopping list instance. add (iteml); instance. add (item2); // Check the indexof method when the grocery item appears in the list try \{ assertEquals (1, instance.indexOf (item2)); assertEquals (0, instance.indexof (iteml)); \} catch (Exception el) \{ fail("Shouldn't get here in testindexOf" + el.getmessage ()); \} // Check the indexof method when the grocery item does not appear in // the list try \{ Grocery item3 = new Grocery("Aladin", "book", 3, 15.5f, 2); int index = instance. indexof (item3); \} catch (Exception e2) \{ assertTrue(e2 instanceof ElementNotFoundException); \} // Check the indexof method when the grocery item is null try \{ Grocery obj = null; int index = instance.indexOf (obj); \} catch (Exception e3) \{ assertTrue (e3 instanceof ElementNotFoundException); \} \}Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started