forked from cbfacademy/intro-to-java-course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShowroomTest.java
More file actions
59 lines (43 loc) · 1.58 KB
/
ShowroomTest.java
File metadata and controls
59 lines (43 loc) · 1.58 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
package com.cbfacademy.cars;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertTrue;
@DisplayName(value = "Showroom tests")
public class ShowroomTest extends ClassExerciseTest {
@Test
@DisplayName("Showroom object has a valid getCars method")
public void testShowroomObjectHasValidListMethod() {
List<HashMap<String, Object>> carValues = getCarValues();
List<Car> cars = new Showroom().getCars();
for (HashMap<String, Object> expected : carValues) {
assertTrue(hasMatch(cars, expected));
}
}
private static boolean hasMatch(List<Car> cars, HashMap<String, Object> map) {
for (Car car : cars) {
boolean match = true;
String make = (String) map.get("make");
if (make != null && !car.getMake().equals(make)) {
match = false;
}
String model = (String) map.get("model");
if (model != null && !car.getModel().equals(model)) {
match = false;
}
String colour = (String) map.get("colour");
if (colour != null && !car.getColour().equalsIgnoreCase(colour)) {
match = false;
}
Integer year = (Integer) map.get("year");
if (year != null && car.getYear() != year) {
match = false;
}
if (match) {
return true;
}
}
return false;
}
}