1
- import static org .assertj .core .api .Assertions .assertThat ;
1
+ import org .junit .jupiter .api .DisplayName ;
2
+ import org .junit .jupiter .api .Tag ;
3
+ import org .junit .jupiter .api .Test ;
4
+
5
+ import static org .assertj .core .api .Assertions .*;
2
6
3
- import org .junit .Test ;
4
7
5
8
public class NeedForSpeedTest {
9
+
6
10
@ Test
11
+ @ Tag ("task:3" )
12
+ @ DisplayName ("The distanceDriven method returns 0 on a new car" )
7
13
public void new_remote_control_car_has_not_driven_any_distance () {
8
14
int speed = 10 ;
9
15
int batteryDrain = 2 ;
@@ -13,6 +19,8 @@ public void new_remote_control_car_has_not_driven_any_distance() {
13
19
}
14
20
15
21
@ Test
22
+ @ Tag ("task:3" )
23
+ @ DisplayName ("The distanceDriven method returns 5 after driving once" )
16
24
public void drive_increases_distance_driven_with_speed () {
17
25
int speed = 5 ;
18
26
int batteryDrain = 1 ;
@@ -24,6 +32,8 @@ public void drive_increases_distance_driven_with_speed() {
24
32
}
25
33
26
34
@ Test
35
+ @ Tag ("task:3" )
36
+ @ DisplayName ("The distanceDriven method returns the correct distance after driving multiple times" )
27
37
public void drive_does_not_increase_distance_driven_when_battery_drained () {
28
38
int speed = 9 ;
29
39
int batteryDrain = 50 ;
@@ -40,6 +50,8 @@ public void drive_does_not_increase_distance_driven_when_battery_drained() {
40
50
}
41
51
42
52
@ Test
53
+ @ Tag ("task:4" )
54
+ @ DisplayName ("The batteryDrained method returns false when car never drove" )
43
55
public void new_remote_control_car_battery_is_not_drained () {
44
56
int speed = 15 ;
45
57
int batteryDrain = 3 ;
@@ -49,6 +61,8 @@ public void new_remote_control_car_battery_is_not_drained() {
49
61
}
50
62
51
63
@ Test
64
+ @ Tag ("task:4" )
65
+ @ DisplayName ("The batteryDrained method returns false when car battery did not completely drain after driving" )
52
66
public void drive_to_almost_drain_battery () {
53
67
int speed = 2 ;
54
68
int batteryDrain = 1 ;
@@ -63,6 +77,8 @@ public void drive_to_almost_drain_battery() {
63
77
}
64
78
65
79
@ Test
80
+ @ Tag ("task:4" )
81
+ @ DisplayName ("The batteryDrained method returns true when battery completely drained after driving" )
66
82
public void drive_until_battery_is_drained () {
67
83
int speed = 2 ;
68
84
int batteryDrain = 1 ;
@@ -77,25 +93,33 @@ public void drive_until_battery_is_drained() {
77
93
}
78
94
79
95
@ Test
96
+ @ Tag ("task:5" )
97
+ @ DisplayName ("The distanceDriven method returns 0 on a new nitro car" )
80
98
public void nitro_car_has_not_driven_any_distance () {
81
99
var car = NeedForSpeed .nitro ();
82
100
assertThat (car .distanceDriven ()).isEqualTo (0 );
83
101
}
84
102
85
103
@ Test
104
+ @ Tag ("task:5" )
105
+ @ DisplayName ("The batteryDrained method returns false when nitro car never drove" )
86
106
public void nitro_car_has_battery_not_drained () {
87
107
var car = NeedForSpeed .nitro ();
88
108
assertThat (car .batteryDrained ()).isFalse ();
89
109
}
90
110
91
111
@ Test
112
+ @ Tag ("task:5" )
113
+ @ DisplayName ("The distanceDriven method returns the correct distance after driving a nitro car" )
92
114
public void nitro_car_has_correct_speed () {
93
115
var car = NeedForSpeed .nitro ();
94
116
car .drive ();
95
117
assertThat (car .distanceDriven ()).isEqualTo (50 );
96
118
}
97
119
98
120
@ Test
121
+ @ Tag ("task:5" )
122
+ @ DisplayName ("The batteryDrained method returns false when nitro battery did not completely drain after driving" )
99
123
public void nitro_has_correct_battery_drain () {
100
124
var car = NeedForSpeed .nitro ();
101
125
@@ -105,14 +129,25 @@ public void nitro_has_correct_battery_drain() {
105
129
}
106
130
107
131
assertThat (car .batteryDrained ()).isFalse ();
132
+ }
108
133
109
- // Drain the battery
110
- car .drive ();
134
+ @ Test
135
+ @ Tag ("task:5" )
136
+ @ DisplayName ("The batteryDrained method returns true when nitro battery completely drained after driving" )
137
+ public void nitro_battery_completely_drains () {
138
+ var car = NeedForSpeed .nitro ();
139
+
140
+ // The battery is almost drained
141
+ for (var i = 0 ; i < 25 ; i ++) {
142
+ car .drive ();
143
+ }
111
144
112
145
assertThat (car .batteryDrained ()).isTrue ();
113
146
}
114
147
115
148
@ Test
149
+ @ Tag ("task:6" )
150
+ @ DisplayName ("The tryFinishCar method returns true when car can finish a race" )
116
151
public void car_can_finish_with_car_that_can_easily_finish () {
117
152
int speed = 10 ;
118
153
int batteryDrain = 2 ;
@@ -125,6 +160,8 @@ public void car_can_finish_with_car_that_can_easily_finish() {
125
160
}
126
161
127
162
@ Test
163
+ @ Tag ("task:6" )
164
+ @ DisplayName ("The tryFinishCar method returns true when car can just finish a race" )
128
165
public void car_can_finish_with_car_that_can_just_finish () {
129
166
int speed = 2 ;
130
167
int batteryDrain = 10 ;
@@ -137,6 +174,8 @@ public void car_can_finish_with_car_that_can_just_finish() {
137
174
}
138
175
139
176
@ Test
177
+ @ Tag ("task:6" )
178
+ @ DisplayName ("The tryFinishCar method returns false when car just cannot finish a race" )
140
179
public void car_can_finish_with_car_that_just_cannot_finish () {
141
180
int speed = 3 ;
142
181
int batteryDrain = 20 ;
@@ -149,6 +188,8 @@ public void car_can_finish_with_car_that_just_cannot_finish() {
149
188
}
150
189
151
190
@ Test
191
+ @ Tag ("task:6" )
192
+ @ DisplayName ("The tryFinishCar method returns false when car cannot finish a race" )
152
193
public void car_can_finish_with_car_that_cannot_finish () {
153
194
int speed = 1 ;
154
195
int batteryDrain = 20 ;
0 commit comments