44
55import java .util .concurrent .TimeUnit ;
66
7+ import org .junit .Before ;
78import org .junit .BeforeClass ;
89import org .junit .Rule ;
910import org .junit .Test ;
@@ -21,24 +22,36 @@ public class ForCommandTest {
2122 @ Rule
2223 public Timeout globalTimeout = new Timeout (100 , TimeUnit .MILLISECONDS );
2324
25+ private MockCommand mockCommand ;
26+ private Command loopCommand ;
27+
2428 @ BeforeClass
2529 public static void setUpBeforeClass () throws Exception {
2630 UnitTestUtility .setupMockBase ();
2731 }
2832
29- @ Test
30- public void testForLoop () {
31- MockCommand mockCommand = new MockCommand ();
33+ @ Before
34+ public void setUp () {
35+ mockCommand = new MockCommand ();
3236 mockCommand .setHasFinished (true );
33- Command loopCommand = new CommandBuilder ()
37+ loopCommand = new CommandBuilder ()
3438 .forLoop (10 , mockCommand )
3539 .build ();
40+ Scheduler .getInstance ().removeAll ();
41+ }
42+
43+ private void runLoopOnce () {
3644 loopCommand .start ();
3745 Scheduler .getInstance ().run ();
3846
3947 while (loopCommand .isRunning ()) {
4048 Scheduler .getInstance ().run ();
4149 }
50+ }
51+
52+ @ Test
53+ public void testForLoop () {
54+ runLoopOnce ();
4255
4356 assertEquals (10 , mockCommand .getExecuteCount ());
4457 assertEquals (10 , mockCommand .getIsFinishedCount ());
@@ -47,4 +60,15 @@ public void testForLoop() {
4760 assertEquals (0 , mockCommand .getInterruptedCount ());
4861 }
4962
63+ @ Test
64+ public void testMultipleRuns () {
65+ runLoopOnce ();
66+ runLoopOnce ();
67+
68+ assertEquals (20 , mockCommand .getExecuteCount ());
69+ assertEquals (20 , mockCommand .getIsFinishedCount ());
70+ assertEquals (20 , mockCommand .getInitializeCount ());
71+ assertEquals (20 , mockCommand .getEndCount ());
72+ assertEquals (0 , mockCommand .getInterruptedCount ());
73+ }
5074}
0 commit comments