Skip to content

Commit

Permalink
Call setUp manually
Browse files Browse the repository at this point in the history
  • Loading branch information
PashaBarahimi committed Dec 14, 2023
1 parent 0ea757f commit a9a06d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Baloot2/src/test/java/domain/EngineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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));
Expand All @@ -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);
Expand All @@ -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));
Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions Baloot2/src/test/java/domain/OrderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}};
Expand All @@ -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);
}};
Expand All @@ -36,13 +38,15 @@ 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));
}

@Test
@DisplayName("Test order getter and setters")
public void testOrderGetterSetters() {
setUp();
order.setId(1);
order.setCustomer(2);
order.setPrice(3);
Expand Down

0 comments on commit a9a06d7

Please sign in to comment.