Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.hamcrest.Matchers;
- import org.junit.After;
- import org.junit.Assert;
- import org.junit.Before;
- import org.junit.jupiter.api.AfterEach;
- import org.junit.jupiter.api.BeforeEach;
- import org.junit.jupiter.api.Test;
- import org.junit.runner.RunWith;
- import org.junit.runners.JUnit4;
- import java.time.LocalTime;
- import java.time.format.DateTimeFormatter;
- import java.util.Map;
- import java.util.TreeMap;
- @RunWith(JUnit4.class)
- class SupermarketTest {
- LocalTime openTime = LocalTime.parse("12:00:00");
- LocalTime closeTime = LocalTime.parse("12:05:00");
- LocalTime newOpenTime = LocalTime.parse("07:00:00");
- LocalTime newCloseTime = LocalTime.parse("23:00:00");
- FIFOCashier Testobject1 = new FIFOCashier("Testobject1");
- Product testpropduct = new Product("A111", "Productexpansion", 21);
- Supermarket supermarket;
- @BeforeEach
- void setUp() {
- if (this.supermarket == null) {
- this.supermarket = Supermarket.importFromXML("jambi2.xml");
- }
- }
- @Test
- void openingHoursReadCorrectly() {
- LocalTime openAt = this.supermarket.getOpenTime();
- LocalTime closeAt = this.supermarket.getClosingTime();
- Assert.assertEquals(this.openTime, openAt);
- Assert.assertEquals(this.closeTime, closeAt);
- }
- @Test
- void anteMeridiemOrPostMeridiem () {
- LocalTime openAt = this.supermarket.getOpenTime();
- LocalTime closeAt = this.supermarket.getClosingTime();
- LocalTime conversedOpenAt = openAt.plusHours(12);
- LocalTime conversedCloseAt = closeAt.plusHours(12);
- Assert.assertFalse(openAt == conversedOpenAt );
- Assert.assertFalse(closeAt == conversedCloseAt );
- }
- // Checking if system handles AM and PM well (Ante meridiem en post meridiem)
- @Test
- void openingHoursUpdateCorrectly() {
- this.supermarket.setOpenTime(newOpenTime);
- this.supermarket.setClosingTime(newCloseTime);
- Assert.assertEquals(newOpenTime, this.supermarket.getOpenTime());
- Assert.assertEquals(newCloseTime, this.supermarket.getClosingTime());
- }
- @Test
- void productsTotalCorrect() {
- Assert.assertTrue( this.supermarket.getProducts().size() == 5);
- }
- @Test
- void expandProductRange() {
- int initialAmount = this.supermarket.getProducts().size();
- this.supermarket.getProducts().add(testpropduct);
- Matchers.equalTo(this.supermarket.getProducts().size() == initialAmount + 1);
- Matchers.contains(this.supermarket.getProducts(), testpropduct); Assert.assertEquals(initialAmount + 1, this.supermarket.getProducts().size());
- }
- @Test
- void clearStockTest() {
- int initialAmount = this.supermarket.getProducts().size();
- this.supermarket.getProducts().clear();
- Assert.assertEquals(0, this.supermarket.getProducts().size());
- }
- @Test
- void addRandomCustomers() {
- this.supermarket.getCustomers().clear();
- Assert.assertTrue( this.supermarket.getCustomers().size() == 0);
- int random = (int) Math.random();
- this.supermarket.addRandomCustomers(random, random);
- Assert.assertTrue(this.supermarket.getCustomers().size() == random);
- }
- @Test
- void hireEmployeeTest(){
- Assert.assertEquals(0, supermarket.getCashiers().size());
- this.supermarket.getCashiers().add(Testobject1);
- Assert.assertEquals(1, supermarket.getCashiers().size());
- }
- @Test
- void customersSetCorrectly() {
- Assert.assertEquals(2, this.supermarket.getCustomers().size());
- }
- @Test
- void calculateTotalNumberOfPurchasedItems() {
- Assert.assertEquals(3, this.supermarket.getTotalNumberOfItems());
- }
- // Re-read supermarket to clean
- @AfterEach
- void after() {
- this.supermarket = Supermarket.importFromXML("jambi2.xml");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement