-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWareHouseTest.java
More file actions
178 lines (152 loc) · 5.71 KB
/
Copy pathWareHouseTest.java
File metadata and controls
178 lines (152 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.Set;
import java.util.Iterator;
import java.util.Map;
/**
* The test class WareHouseTest.
*
* @version 2024.10.07 DP classes
*/
public class WareHouseTest {
private WareHouse wareHouse;
private Order order1;
private Order order2;
private Order order3;
private DeliveryPerson dp1;
/**
* Default constructor for test class WareHouseTest
*/
public WareHouseTest() {
}
/**
* Sets up the test fixture.
*
* Called before every test case method.
*/
@Before
public void setUp() {
this.wareHouse = new WareHouse();
this.order1 = new UrgentOrder("Alice", new Location(1, 1), new Location(2, 2), 10, 1.0, "Sender1", Surcharge.MEDIUM, Urgency.EMERGENCY);
this.order2 = new MedicalOrder("Bob", new Location(3, 3), new Location(4, 4), 5, 2.0, "Sender2", Urgency.IMPORTANT);
this.order3 = new NonUrgentOrder("Charlie", new Location(5, 5), new Location(6, 6), 10, 1.5, "Sender3", Surcharge.LOW, Urgency.NONESSENTIAL);
this.dp1 = new CommonDP(new DeliveryCompany("Company1"), new Location(3, 3), "DP1");
}
/**
* Tears down the test fixture.
*
* Called after every test case method.
*/
@After
public void tearDown() {
System.out.println("Tearing down the test environment...");
this.wareHouse = null;
this.order1 = null;
this.order2 = null;
this.order3 = null;
this.dp1 = null;
System.out.println("Teardown complete.");
}
/**
* Test adding orders to the warehouse.
*/
@Test
public void testAddOrder() {
this.wareHouse.addOrder(this.order1);
this.wareHouse.addOrder(this.order2);
this.wareHouse.addOrder(this.order3);
Set<Order> orders = this.wareHouse.getOrders();
Iterator<Order> iterator = orders.iterator();
System.out.println("Orders in warehouse after adding:");
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
assertEquals(3, orders.size());
// Check the order based on sorting logic (urgency > delivery time > destination name)
iterator = orders.iterator();
assertEquals(this.order1, iterator.next()); // Highest urgency (EMERGENCY)
assertEquals(this.order2, iterator.next()); // Second highest urgency (IMPORTANT)
assertEquals(this.order3, iterator.next()); // Lowest urgency (NONESSENTIAL)
}
@Test
public void testAddDeliveredOrder() {
this.wareHouse.addDeliveredOrder(this.order1, this.dp1);
Map<Order, DeliveryPerson> deliveredOrders = this.wareHouse.getDeliveredOrders();
assertEquals(1, deliveredOrders.size());
assertTrue(deliveredOrders.containsKey(this.order1));
assertEquals(this.dp1, deliveredOrders.get(this.order1));
}
/**
* Test getting delivered orders from the warehouse.
*/
@Test
public void testGetDeliveredOrders() {
this.wareHouse.addDeliveredOrder(this.order1, this.dp1);
Map<Order, DeliveryPerson> deliveredOrders = this.wareHouse.getDeliveredOrders();
assertNotNull(deliveredOrders);
assertEquals(1, deliveredOrders.size());
assertTrue(deliveredOrders.containsKey(this.order1));
assertEquals(this.dp1, deliveredOrders.get(this.order1));
}
/**
* Test retrieving the first order from the warehouse.
*/
@Test
public void testRetrieveFirstOrder() {
this.wareHouse.addOrder(this.order1);
this.wareHouse.addOrder(this.order2);
Order retrievedOrder = this.wareHouse.retrieveFirstOrder();
System.out.println("First retrieved order: " + retrievedOrder);
assertEquals(this.order1, retrievedOrder); // Order with highest urgency
assertEquals(1, this.wareHouse.getOrders().size());
retrievedOrder = this.wareHouse.retrieveFirstOrder();
System.out.println("Second retrieved order: " + retrievedOrder);
assertEquals(this.order2, retrievedOrder); // Next highest urgency
assertTrue(this.wareHouse.getOrders().isEmpty()); // No more orders
}
/**
* Test getting the location of the warehouse.
*/
@Test
public void testGetLocation() {
Location location = this.wareHouse.getLocation();
System.out.println("Warehouse location: " + location);
assertEquals(5, location.getX());
assertEquals(5, location.getY());
}
/**
* Test getting all orders from the warehouse.
*/
@Test
public void testGetAllOrders() {
this.wareHouse.addOrder(this.order1);
this.wareHouse.addOrder(this.order2);
this.wareHouse.addOrder(this.order3);
Set<Order> orders = this.wareHouse.getOrders();
assertEquals(3, orders.size());
assertTrue(orders.contains(this.order1));
assertTrue(orders.contains(this.order2));
assertTrue(orders.contains(this.order3));
}
/**
* Test handling duplicate orders.
*/
@Test
public void testHandleDuplicateOrders() {
this.wareHouse.addOrder(this.order1);
this.wareHouse.addOrder(this.order1); // Add the same order again
Set<Order> orders = this.wareHouse.getOrders();
assertEquals(1, orders.size()); // Should still be 1 if duplicates are not allowed
}
/**
* Test behavior with an empty warehouse.
*/
@Test
public void testEmptyWarehouse() {
assertTrue(this.wareHouse.getOrders().isEmpty());
Order retrievedOrder = this.wareHouse.retrieveFirstOrder();
assertNull(retrievedOrder); // Should return null if no orders are present
}
}