Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. import org.hamcrest.Matchers;
  2. import org.junit.After;
  3. import org.junit.Assert;
  4. import org.junit.Before;
  5. import org.junit.jupiter.api.AfterEach;
  6. import org.junit.jupiter.api.BeforeEach;
  7. import org.junit.jupiter.api.Test;
  8. import org.junit.runner.RunWith;
  9. import org.junit.runners.JUnit4;
  10.  
  11. import java.time.LocalTime;
  12. import java.time.format.DateTimeFormatter;
  13. import java.util.Map;
  14. import java.util.TreeMap;
  15.  
  16. @RunWith(JUnit4.class)
  17. class SupermarketTest {
  18.  
  19. LocalTime openTime = LocalTime.parse("12:00:00");
  20. LocalTime closeTime = LocalTime.parse("12:05:00");
  21. LocalTime newOpenTime = LocalTime.parse("07:00:00");
  22. LocalTime newCloseTime = LocalTime.parse("23:00:00");
  23. FIFOCashier Testobject1 = new FIFOCashier("Testobject1");
  24. Product testpropduct = new Product("A111", "Productexpansion", 21);
  25. Supermarket supermarket;
  26.  
  27. @BeforeEach
  28. void setUp() {
  29. if (this.supermarket == null) {
  30. this.supermarket = Supermarket.importFromXML("jambi2.xml");
  31. }
  32. }
  33.  
  34. @Test
  35. void openingHoursReadCorrectly() {
  36. LocalTime openAt = this.supermarket.getOpenTime();
  37. LocalTime closeAt = this.supermarket.getClosingTime();
  38.  
  39. Assert.assertEquals(this.openTime, openAt);
  40. Assert.assertEquals(this.closeTime, closeAt);
  41. }
  42. @Test
  43. void anteMeridiemOrPostMeridiem () {
  44. LocalTime openAt = this.supermarket.getOpenTime();
  45. LocalTime closeAt = this.supermarket.getClosingTime();
  46. LocalTime conversedOpenAt = openAt.plusHours(12);
  47. LocalTime conversedCloseAt = closeAt.plusHours(12);
  48. Assert.assertFalse(openAt == conversedOpenAt );
  49. Assert.assertFalse(closeAt == conversedCloseAt );
  50. }
  51.  
  52. // Checking if system handles AM and PM well (Ante meridiem en post meridiem)
  53. @Test
  54. void openingHoursUpdateCorrectly() {
  55. this.supermarket.setOpenTime(newOpenTime);
  56. this.supermarket.setClosingTime(newCloseTime);
  57. Assert.assertEquals(newOpenTime, this.supermarket.getOpenTime());
  58. Assert.assertEquals(newCloseTime, this.supermarket.getClosingTime());
  59. }
  60.  
  61. @Test
  62. void productsTotalCorrect() {
  63. Assert.assertTrue( this.supermarket.getProducts().size() == 5);
  64. }
  65.  
  66. @Test
  67. void expandProductRange() {
  68. int initialAmount = this.supermarket.getProducts().size();
  69. this.supermarket.getProducts().add(testpropduct);
  70. Matchers.equalTo(this.supermarket.getProducts().size() == initialAmount + 1);
  71. Matchers.contains(this.supermarket.getProducts(), testpropduct); Assert.assertEquals(initialAmount + 1, this.supermarket.getProducts().size());
  72. }
  73.  
  74. @Test
  75. void clearStockTest() {
  76. int initialAmount = this.supermarket.getProducts().size();
  77. this.supermarket.getProducts().clear();
  78. Assert.assertEquals(0, this.supermarket.getProducts().size());
  79. }
  80.  
  81. @Test
  82. void addRandomCustomers() {
  83. this.supermarket.getCustomers().clear();
  84. Assert.assertTrue( this.supermarket.getCustomers().size() == 0);
  85. int random = (int) Math.random();
  86. this.supermarket.addRandomCustomers(random, random);
  87. Assert.assertTrue(this.supermarket.getCustomers().size() == random);
  88. }
  89.  
  90.  
  91. @Test
  92. void hireEmployeeTest(){
  93. Assert.assertEquals(0, supermarket.getCashiers().size());
  94. this.supermarket.getCashiers().add(Testobject1);
  95. Assert.assertEquals(1, supermarket.getCashiers().size());
  96.  
  97. }
  98. @Test
  99. void customersSetCorrectly() {
  100. Assert.assertEquals(2, this.supermarket.getCustomers().size());
  101. }
  102.  
  103. @Test
  104. void calculateTotalNumberOfPurchasedItems() {
  105. Assert.assertEquals(3, this.supermarket.getTotalNumberOfItems());
  106. }
  107.  
  108. // Re-read supermarket to clean
  109. @AfterEach
  110. void after() {
  111. this.supermarket = Supermarket.importFromXML("jambi2.xml");
  112. }
  113.  
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement