You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.9 KiB

  1. package de.hs_fulda.ciip.projjpn;
  2. import junit.framework.TestCase;
  3. public class ItemTest extends TestCase {
  4. /**
  5. * No Items are in Stock.
  6. * Check the inStock() Method.
  7. */
  8. public void test_ItemNotInStock() {
  9. // Given
  10. Item item = new Item();
  11. // When
  12. boolean notInStock = item.inStock();
  13. // Then
  14. assertFalse(notInStock);
  15. }
  16. /**
  17. * Stock is not Empty.
  18. * Check the inStock() Method.
  19. */
  20. public void test_ItemInStock() {
  21. // Given
  22. Item item = new Item();
  23. item.updateAvailability(1);
  24. // When
  25. boolean inStock = item.inStock();
  26. // Then
  27. assertTrue(inStock);
  28. }
  29. /**
  30. * One and the same type of an item costs the same.
  31. * check getCurrentPrice()
  32. */
  33. public void test_priceOfMultipleIdenticalItems() {
  34. // Given
  35. Item item = new Item();
  36. int quantity = 3;
  37. float price = 5;
  38. item.updateAvailability(quantity);
  39. item.updatePrice(price);
  40. // When
  41. float expectedPrice = quantity * price;
  42. // Then
  43. float actualPrice = 0;
  44. for(int i = 0; i < quantity; i++) {
  45. actualPrice += item.getCurrentPrice();
  46. }
  47. assertEquals(expectedPrice, actualPrice);
  48. }
  49. public void test_buildCompleteItem() {
  50. // Given
  51. String expectedTitel = "Logitec Maus";
  52. String expectedDescription = "Gaming Maus fuer Fortgeschrittene.";
  53. int expectedQuantity = 10;
  54. float expectedPrice = 69.99f;
  55. // When
  56. Item itemNotNull = new Item(expectedTitel, expectedDescription, expectedQuantity, expectedPrice);
  57. // Then
  58. assertNotNull(itemNotNull);
  59. // When
  60. boolean validDescription = itemNotNull.getDescription().equals(expectedDescription);
  61. assertTrue(validDescription);
  62. boolean validTitle = itemNotNull.getTitel().equals(expectedTitel);
  63. assertTrue(validTitle);
  64. boolean validQuantity = itemNotNull.getCurrentStock() == expectedQuantity;
  65. assertTrue(validQuantity);
  66. boolean validPrice = itemNotNull.getCurrentPrice() == expectedPrice;
  67. assertTrue(validPrice);
  68. }
  69. }