Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 10 Weeks Ago, 5 Days Ago |
Questions Answered: | 4870 |
Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Write a unit test for addInventory(). Call redSweater.addInventory() with parameter sweaterShipment. Print the shown error if the subsequent quantity is incorrect. Sample output for failed unit test given initial quantity is 10 and sweaterShipment is 50:
Beginning tests. UNIT TEST FAILED: addInventory() Tests complete.
Note: UNIT TEST FAILED is preceded by 3 spaces.
Â
// ===== Code from file InventoryTag.java =====
public class InventoryTag {
  private int quantityRemaining;
Â
  public InventoryTag() {
     quantityRemaining = 0;
  }
Â
  public int getQuantityRemaining() {
     return quantityRemaining;
  }
Â
  public void addInventory(int numItems) {
     if (numItems > 10) {
        quantityRemaining = quantityRemaining + numItems;
     }
     return;
  }
}
// ===== end =====
Â
// ===== Code from file CallInventoryTag.java =====
public class CallInventoryTag {
  public static void main (String [] args) {
     InventoryTag redSweater = new InventoryTag();
     int sweaterShipment = 0;
     int sweaterInventoryBefore = 0;
Â
     sweaterInventoryBefore = redSweater.getQuantityRemaining();
     sweaterShipment = 25;
Â
     System.out.println("Beginning tests.");
Â
     // FIXME add unit test for addInventory
Â
     /* Your solution goes here */
Â
     System.out.println("Tests complete.");
Â
     return;
  }
}
// ===== end =====