File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
FiniteStateMachine/src/test/java/com/iluwater Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 55import com .iluwatar .trafficlight .GreenLightState ;
66import com .iluwatar .trafficlight .RedLightState ;
77import com .iluwatar .trafficlight .TrafficLightContext ;
8+ import com .iluwatar .trafficlight .TrafficLightFsm ;
89import com .iluwatar .trafficlight .YellowLightState ;
910import org .junit .jupiter .api .BeforeEach ;
1011import 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+
You can’t perform that action at this time.
0 commit comments