Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer the following question ASAP. Write Unit tests as JUnit tests in the file BasketTesting.java file for the methods that are in the given

Please answer the following question ASAP.
Write Unit tests as JUnit tests in the file BasketTesting.java file for the methods that are in the given BasketTwelve.java, which implements the Basket.java file (interface).
The tests should test the methods written in the BasketTwelve.java implementation using sophisticated assertions that fail on the implementation.
Here below are the given files.
1) Basket.java image text in transcribed
2) Item.java
image text in transcribed
3) BasketTwelve.java
image text in transcribed
4) BasketTesting.java
image text in transcribed
Basket.java 1 package student 3 public interface Basket ereturn the total count of all itens, counting duplicates, in the basket int counto s eparam i The item to count ereturn The number of the provided item that are in the basket int countItem(Iten 1): 12 13 ereturn the total cost in cents of all items in the basket, count ing duplicates 15 16 17 int totatCost) eparan1 The item to add 19 21 23 25 void addToBasketItem t) Remove a single copy of an item fron the basket eparam1 The Iten to renove ereturn false if the item was not in the basket, true otherwise bootean removeFromBasket(Item i) Remove all copies of an ites from the basket eparam 1 The Iten to renove ereturn false if the item was not in the basket, true otherwise 29 31 32 bootean removeALLFromBasket (Item i) Remove all items from the basket 35 void enptyD 37 tem.java 1 package student; 3 public class Iten String name; int priceInCents; public Iten(String name, int priceInCents) this nane nane: this priceInCents- priceInCents: gOverride public boolean equats(Object other) iTC!Cother instanceof Item)) return false: 14 Item i (Item)other; return i.name.equals(this.name) &&i.priceInCentsthis-priceInCents; 19) BasketTwelve.java package student 3 inport java.util.ArrayList; 5 public class Basket12 inplements Basket t public Basket12) this.items new ArrayList BANNS Arrays.asList(new Object Ite 1. 2,(3), 44), 5, 6), (7, (8, (9), (10e), 11), (12) 15 16 17 private int bagType public BasketTest int bagType) 19 super); this bagType bagType; 21 arameterized . Parameters(nane "Basket( index)") public static Collectioncobjectll> bags) ( return BAGNUMS; private Basket makeBasket) switch(this.bagType) 29 case 8: return new Baskete); case 1: return new Basket10: case 2: return new Basket20 case 3: return new Basket30; case 4: return new Basket40 case 5: return new Basket5); case 6: return new Basket6); case 7: return new Basket70: case 8: return new Basket8) case 9: return new Basket9); case 18: return new Basket1e0: case 11: return new Basket110: case 12: return new Basket120: 32 34 35 36 38 return null; Basket.java 1 package student 3 public interface Basket ereturn the total count of all itens, counting duplicates, in the basket int counto s eparam i The item to count ereturn The number of the provided item that are in the basket int countItem(Iten 1): 12 13 ereturn the total cost in cents of all items in the basket, count ing duplicates 15 16 17 int totatCost) eparan1 The item to add 19 21 23 25 void addToBasketItem t) Remove a single copy of an item fron the basket eparam1 The Iten to renove ereturn false if the item was not in the basket, true otherwise bootean removeFromBasket(Item i) Remove all copies of an ites from the basket eparam 1 The Iten to renove ereturn false if the item was not in the basket, true otherwise 29 31 32 bootean removeALLFromBasket (Item i) Remove all items from the basket 35 void enptyD 37 tem.java 1 package student; 3 public class Iten String name; int priceInCents; public Iten(String name, int priceInCents) this nane nane: this priceInCents- priceInCents: gOverride public boolean equats(Object other) iTC!Cother instanceof Item)) return false: 14 Item i (Item)other; return i.name.equals(this.name) &&i.priceInCentsthis-priceInCents; 19) BasketTwelve.java package student 3 inport java.util.ArrayList; 5 public class Basket12 inplements Basket t public Basket12) this.items new ArrayList BANNS Arrays.asList(new Object Ite 1. 2,(3), 44), 5, 6), (7, (8, (9), (10e), 11), (12) 15 16 17 private int bagType public BasketTest int bagType) 19 super); this bagType bagType; 21 arameterized . Parameters(nane "Basket( index)") public static Collectioncobjectll> bags) ( return BAGNUMS; private Basket makeBasket) switch(this.bagType) 29 case 8: return new Baskete); case 1: return new Basket10: case 2: return new Basket20 case 3: return new Basket30; case 4: return new Basket40 case 5: return new Basket5); case 6: return new Basket6); case 7: return new Basket70: case 8: return new Basket8) case 9: return new Basket9); case 18: return new Basket1e0: case 11: return new Basket110: case 12: return new Basket120: 32 34 35 36 38 return null

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions