-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrafficLightTest.java
More file actions
47 lines (40 loc) · 1.22 KB
/
TrafficLightTest.java
File metadata and controls
47 lines (40 loc) · 1.22 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
/*
* JUnit5 test class
*/
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
public class TrafficLightTest{
TrafficLight light1, light2, light3;
@BeforeEach
public void init(){
light1 = new TrafficLight('G');
light2 = new TrafficLight('Y');
light3 = new TrafficLight('R');
}
@Test
public void testDefConst(){
assertEquals(light3.getColor(), 'R');
}
@Test
public void testInit1(){
boolean b1, b2, b3;
b1 = light1.getColor() != light2.getColor();
b2 = light2.getColor() != light3.getColor();
b3 = light3.getColor() != light1.getColor();
assertTrue(b1 && b2 && b3);
}
@Test
public void testConst(){
boolean b1, b2;
b1 = light1.getColor() == 'G';
b2 = light2.getColor() == 'Y';
assertTrue(b1 && b2);
}
@Test
public void testSetter(){
light2.setColor('R');
assertEquals(light2.getColor(), light3.getColor());
}
}