Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

E zy ks My library es 140 home >3.7: Unit testing (classes) zyBooks catalog Help

ID: 3741952 • Letter: E

Question

E zy ks My library es 140 home >3.7: Unit testing (classes) zyBooks catalog Help/FAQ hannah consigio Write a unit test for addinventoryo. Call redsweater addinventory) wilth parameter sweatershipment Print the shown error i tve subsequent quantity is incorrect. Sample output for failed unit test given initial quantity is 10 and sweaterShipment is s0 Beginning tests. UNIT TEST FAILED: addInventory() Tests complete. Note: UNIT TEST FAILED is preceded by 3 spaces 1 11 Code from file Inventory Tag.java 2 public class InventoryTag ( 3 private int quantityRemaining 5 public InventoryTag) ( quantityRemaining - 9 public int getQuantityRemaining) ( return quantityRenaining 12 13 public void addInventory(int numitems) ( if (numItems 10) t quantityRemaining -quantityRemaining numItess; O Type here to search

Explanation / Answer

Please find the code for the missing parts below.

CODE

==================

redSweater.addInventory(sweaterShipment);

int actualSweaterInventoryAfter = redSweater.getQuantityRemaining();

int expectedSweaterInventoryAfter;

if (sweaterShipment > 10) {

expectedSweaterInventoryAfter = sweaterInventoryBefore + sweaterShipment;

} else {

expectedSweaterInventoryAfter = sweaterInventoryBefore;

}

if (expectedSweaterInventoryAfter == actualSweaterInventoryAfter) {

System.out.println(" UNIT TEST PASSED: addInventory()");

} else {

System.out.println(" UNIT TEST FAILED: addInventory()");

}