From a9a06d781a313d77e24a31c5475366182055c7c3 Mon Sep 17 00:00:00 2001 From: Pasha Barahimi Date: Thu, 14 Dec 2023 14:09:55 +0330 Subject: [PATCH] Call setUp manually --- Baloot2/src/test/java/domain/EngineTest.java | 12 ++++++++++++ Baloot2/src/test/java/domain/OrderTest.java | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/Baloot2/src/test/java/domain/EngineTest.java b/Baloot2/src/test/java/domain/EngineTest.java index 775313f..c899e62 100644 --- a/Baloot2/src/test/java/domain/EngineTest.java +++ b/Baloot2/src/test/java/domain/EngineTest.java @@ -42,6 +42,7 @@ public void testAverageQuantityOneOrder() { @Test @DisplayName("Test average quantity with multiple orders") public void testAverageQuantityMultipleOrders() { + setUp(); Order order = constructOrder(0, 1, 4, 2); Order order2 = constructOrder(1, 1, 8, 6); engine.orderHistory.add(order); @@ -52,6 +53,7 @@ public void testAverageQuantityMultipleOrders() { @Test @DisplayName("Test average quantity with unknown customer") public void testAverageQuantityUnknownCustomer() { + setUp(); Order order = constructOrder(0, 1, 4, 2); engine.orderHistory.add(order); Assertions.assertThrows(Exception.class, () -> engine.getAverageOrderQuantityByCustomer(2)); @@ -62,12 +64,14 @@ public void testAverageQuantityUnknownCustomer() { @Test @DisplayName("Test quantity pattern with no orders") public void testQuantityPatternNoOrders() { + setUp(); Assertions.assertEquals(0, engine.getQuantityPatternByPrice(1)); } @Test @DisplayName("Test quantity pattern with linear increasing quantity for a price") public void testQuantityPatternWithPattern() { + setUp(); Order order = constructOrder(0, 1, 4, 2); Order order2 = constructOrder(1, 2, 4, 8); Order order3 = constructOrder(2, 2, 4, 14); @@ -80,6 +84,7 @@ public void testQuantityPatternWithPattern() { @Test @DisplayName("Test quantity pattern without pattern") public void testQuantityPatternWithoutPattern() { + setUp(); Order order = constructOrder(0, 1, 4, 2); Order order2 = constructOrder(1, 2, 4, 8); Order order3 = constructOrder(2, 2, 4, 13); @@ -92,6 +97,7 @@ public void testQuantityPatternWithoutPattern() { @Test @DisplayName("Test quantity pattern with pattern and different prices") public void testQuantityPatternWithPatternAndDifferentPrices() { + setUp(); Order order = constructOrder(0, 1, 4, 2); Order order2 = constructOrder(1, 2, 4, 8); Order order3 = constructOrder(2, 2, 5, 13); @@ -108,6 +114,7 @@ public void testQuantityPatternWithPatternAndDifferentPrices() { @Test @DisplayName("Test fraudulent quantity with order quantity more than the average") public void testFraudulentQuantityMoreThanAvg() { + setUp(); Order order = constructOrder(0, 1, 4, 2); Order order2 = constructOrder(1, 1, 8, 6); engine.orderHistory.add(order); @@ -117,6 +124,7 @@ public void testFraudulentQuantityMoreThanAvg() { @Test @DisplayName("Test fraudulent quantity with order quantity equal to the average") public void testFraudulentQuantityEqualToAvg() { + setUp(); Order order = constructOrder(0, 1, 4, 2); engine.orderHistory.add(order); Assertions.assertEquals(0, engine.getCustomerFraudulentQuantity(order)); @@ -125,6 +133,7 @@ public void testFraudulentQuantityEqualToAvg() { @Test @DisplayName("Test fraudulent quantity with order quantity less than the average") public void testFraudulentQuantityLessThanAvg() { + setUp(); Order order = constructOrder(0, 1, 4, 2); Order order2 = constructOrder(1, 1, 8, 6); engine.orderHistory.add(order2); @@ -136,6 +145,7 @@ public void testFraudulentQuantityLessThanAvg() { @Test @DisplayName("Test adding already existing order") public void testAddingAlreadyExistingOrder() { + setUp(); Order order = constructOrder(0, 1, 4, 2); engine.orderHistory.add(order); Assertions.assertEquals(0, engine.addOrderAndGetFraudulentQuantity(order)); @@ -144,6 +154,7 @@ public void testAddingAlreadyExistingOrder() { @Test @DisplayName("Test adding order and getting fraudulent quantity (if not 0)") public void testAddOrderAndGetFraudulent() { + setUp(); Order order = constructOrder(0, 1, 4, 2); Order order2 = constructOrder(1, 1, 8, 6); engine.orderHistory.add(order); @@ -154,6 +165,7 @@ public void testAddOrderAndGetFraudulent() { @Test @DisplayName("Test adding order and getting fraudulent quantity of 0 (should return pattern)") public void testAddOrderAndGetFraudulentBelowAvg() { + setUp(); Order order = constructOrder(0, 1, 4, 8); Order order2 = constructOrder(1, 1, 4, 14); Order order3 = constructOrder(2, 1, 4, 2); diff --git a/Baloot2/src/test/java/domain/OrderTest.java b/Baloot2/src/test/java/domain/OrderTest.java index 8eb29c9..3f01dec 100644 --- a/Baloot2/src/test/java/domain/OrderTest.java +++ b/Baloot2/src/test/java/domain/OrderTest.java @@ -15,6 +15,7 @@ public void setUp() { @Test @DisplayName("Test order.equals should only compare order ids") public void testEqualsComparesIds() { + setUp(); Order order = new Order() {{ setId(0); }}; @@ -27,6 +28,7 @@ public void testEqualsComparesIds() { @Test @DisplayName("Test order.equals with different order ids") public void testEqualsDifferentIds() { + setUp(); Order newOrder = new Order() {{ setId(1); }}; @@ -36,6 +38,7 @@ public void testEqualsDifferentIds() { @Test @DisplayName("Test order.equals with object of another type") public void testEqualsWrongObject() { + setUp(); Object object = new Object(); Assertions.assertFalse(order.equals(object)); } @@ -43,6 +46,7 @@ public void testEqualsWrongObject() { @Test @DisplayName("Test order getter and setters") public void testOrderGetterSetters() { + setUp(); order.setId(1); order.setCustomer(2); order.setPrice(3);