Skip to content

Commit d5c14be

Browse files
committed
updated tests
1 parent b88de19 commit d5c14be

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

FiniteStateMachine/src/test/java/com/iluwater/TrafficLightTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.iluwatar.trafficlight.GreenLightState;
66
import com.iluwatar.trafficlight.RedLightState;
77
import com.iluwatar.trafficlight.TrafficLightContext;
8+
import com.iluwatar.trafficlight.TrafficLightFsm;
89
import com.iluwatar.trafficlight.YellowLightState;
910
import org.junit.jupiter.api.BeforeEach;
1011
import org.junit.jupiter.api.Test;
@@ -151,7 +152,25 @@ void testMultipleCycles() {
151152
context.handleEvent(); // Yellow -> Red
152153
assertTrue(context.getCurrentState() instanceof RedLightState);
153154
}
155+
156+
// Test if state changes properly when reset in the middle of cycles
157+
@Test
158+
void testResetMidCycle() {
159+
context.handleEvent(); // Red -> Green
160+
context.setState(new YellowLightState()); // Manually set Yellow
161+
assertTrue(context.getCurrentState() instanceof YellowLightState);
162+
context.handleEvent(); // Yellow -> Red
163+
assertTrue(context.getCurrentState() instanceof RedLightState);
164+
}
165+
166+
// Test for traffic light FSM running through multiple cycles
167+
@Test
168+
void testTrafficLightFsmCycles() {
169+
// Start the FSM and cycle through multiple events
170+
TrafficLightFsm.main(new String[0]); // This will run the logic in the main function of TrafficLightFsm
171+
}
154172
}
155173

156174

157175

176+

0 commit comments

Comments
 (0)