-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathFurnitureOrderSecondTest.java
91 lines (69 loc) · 2.87 KB
/
FurnitureOrderSecondTest.java
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
package by.andd3dfx.common.furniture;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import java.util.HashMap;
import static junit.framework.TestCase.assertEquals;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class FurnitureOrderSecondTest {
private static FurnitureOrder furnitureFactory;
@BeforeClass
public static void initiate() {
furnitureFactory = new FurnitureOrder();
}
@Test
public void _08_orderNothing() {
furnitureFactory.addToOrder(Furniture.TABLE, 0);
furnitureFactory.addToOrder(Furniture.CHAIR, 0);
furnitureFactory.addToOrder(Furniture.COUCH, 0);
assertEquals(0.0f, furnitureFactory.getTotalOrderCost());
}
@Test
public void _09_placeOrders() {
furnitureFactory.addToOrder(Furniture.TABLE, 6);
furnitureFactory.addToOrder(Furniture.CHAIR, 10);
furnitureFactory.addToOrder(Furniture.COUCH, 5);
assertEquals(5000.0f, furnitureFactory.getTotalOrderCost());
}
@Test
public void _10_validateFurnitureCostAndQuantity() {
HashMap<Furniture, Integer> orderedFurniture = furnitureFactory.getOrderedFurniture();
assertEquals(21, orderedFurniture.values().stream().mapToInt(Integer::intValue).sum());
orderedFurniture.keySet().forEach(furniture -> {
if ("Chair".equals(furniture.label())) {
assertEquals(100.0f, furniture.cost());
}
if ("Table".equals(furniture.label())) {
assertEquals(250.0f, furniture.cost());
}
if ("Couch".equals(furniture.label())) {
assertEquals(500.0f, furniture.cost());
}
});
assertEquals(10, furnitureFactory.getTypeCount(Furniture.CHAIR));
assertEquals(1000.0f, furnitureFactory.getTypeCost(Furniture.CHAIR));
assertEquals(6, furnitureFactory.getTypeCount(Furniture.TABLE));
assertEquals(1500.0f, furnitureFactory.getTypeCost(Furniture.TABLE));
assertEquals(5, furnitureFactory.getTypeCount(Furniture.COUCH));
assertEquals(2500.0f, furnitureFactory.getTypeCost(Furniture.COUCH));
// Validates order size
assertEquals(21, furnitureFactory.getTotalOrderQuantity());
}
@Test
public void _11_validateFurniture() {
for (Furniture f : Furniture.values()) {
switch (f.label()) {
case ("Chair"):
assertEquals(100.0f, f.cost());
break;
case ("Table"):
assertEquals(250.0f, f.cost());
break;
case ("Coach"):
assertEquals(500.0f, f.cost());
break;
}
}
}
}