1616
1717package org .strongback .command ;
1818
19- import static org .fest .assertions .Assertions .assertThat ;
19+ import org .junit .Before ;
20+ import org .junit .Test ;
21+ import org .strongback .Logger ;
2022
2123import java .util .Arrays ;
2224import java .util .LinkedList ;
2325import java .util .List ;
2426import java .util .Queue ;
2527
26- import org .junit .Before ;
27- import org .junit .Test ;
28- import org .strongback .Logger ;
28+ import static org .fest .assertions .Assertions .assertThat ;
2929
3030public class CommandGroupTest {
3131 private Scheduler scheduler ;
@@ -332,6 +332,51 @@ public OtherDiagramFromBoard() {
332332 }
333333 }
334334
335+ @ Test
336+ public void shouldExecuteComposedNamedCommandGroups () {
337+ scheduler .submit (new OuterCommandGroup ());
338+
339+ assertThat (list ).isEmpty ();
340+
341+ // First step should come from the OuterCommandGroup
342+ scheduler .execute (0 );
343+ assertThat (list ).isEqualTo (listOf ("C0 init" , "C0 exe" , "C0 fin" ));
344+ list .clear ();
345+
346+ // Second step should come from NestedCommandGroup
347+ scheduler .execute (0 );
348+ assertThat (list ).isEqualTo (listOf ("C1 init" , "C1 exe" , "C1 fin" ));
349+ list .clear ();
350+
351+ // Third step should come from NestedCommandGroup
352+ scheduler .execute (0 );
353+ assertThat (list ).isEqualTo (listOf ("C2 init" , "C2 exe" , "C2 fin" ));
354+ list .clear ();
355+
356+ // Fourth step should resume the OuterCommandGroup sequence
357+ scheduler .execute (0 );
358+ assertThat (list ).isEqualTo (listOf ("C3 init" , "C3 exe" , "C3 fin" ));
359+ list .clear ();
360+
361+ // Fifth step is empty, nothing executed
362+ scheduler .execute (0 );
363+ assertThat (list ).isEmpty ();
364+ }
365+
366+ private final class OuterCommandGroup extends CommandGroup {
367+ @ SuppressWarnings ("synthetic-access" )
368+ public OuterCommandGroup () {
369+ sequentially (c [0 ], new InnerNamedCommandGroup (), c [3 ]);
370+ }
371+
372+ private final class InnerNamedCommandGroup extends CommandGroup {
373+ @ SuppressWarnings ("synthetic-access" )
374+ public InnerNamedCommandGroup () {
375+ sequentially (c [1 ], c [2 ]);
376+ }
377+ }
378+ }
379+
335380 private static final class TestCommand extends Command {
336381 private static int commandID = 0 ;
337382
@@ -454,4 +499,4 @@ public String toString() {
454499 return "R" + number ;
455500 }
456501 }
457- }
502+ }
0 commit comments