package org.requirementsascode;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

public class IncludeTest extends AbstractTestCase{
    private static final String INCLUDED_USE_CASE = "Included Use Case";

    @Before
    public void setup() {
      setupWith(new TestUseCaseModelRunner());
    }

    @Test
    public void includeBasicFlowOnce() {
      UseCaseModel useCaseModel = useCaseModelBuilder
        .useCase(INCLUDED_USE_CASE)
          .basicFlow()
            .step(SYSTEM_DISPLAYS_NUMBER).user(EnterNumber.class).system(displayEnteredNumber())
        .useCase(USE_CASE)
          .basicFlow()
            .step(SYSTEM_DISPLAYS_TEXT).user(EnterText.class).system(displayEnteredText())
            .include(INCLUDED_USE_CASE)
            .step(SYSTEM_DISPLAYS_TEXT_AGAIN).system(displayConstantText())
        .build();
      
    useCaseModelRunner.run(useCaseModel);
    useCaseModelRunner.reactTo(enterText(), enterNumber());

    String expectedSteps =
        SYSTEM_DISPLAYS_TEXT + ";"
            + SYSTEM_DISPLAYS_NUMBER + ";"
            + SYSTEM_DISPLAYS_TEXT_AGAIN + ";";
    assertEquals(expectedSteps, runStepNames());
  }
    
    @Test
    public void includedBasicFlowCanBeRunOnItsOwn() {
      UseCaseModel useCaseModel = useCaseModelBuilder
        .useCase(INCLUDED_USE_CASE)
          .basicFlow()
            .step(SYSTEM_DISPLAYS_NUMBER).user(EnterNumber.class).system(displayEnteredNumber())
        .useCase(USE_CASE)
          .basicFlow()
            .step(SYSTEM_DISPLAYS_TEXT).user(EnterText.class).system(displayEnteredText())
            .include(INCLUDED_USE_CASE)
        .build();
      
      useCaseModelRunner.run(useCaseModel);
      useCaseModelRunner.reactTo(enterNumber());
      
      assertEquals(SYSTEM_DISPLAYS_NUMBER + ";", runStepNames());
    }
}

@@ -97,16 +97,41 @@
 Before;%0A
+import org.junit.Ignore;%0A
 import o
@@ -1220,18 +1220,16 @@
  %7D%0A    %0A
-  
   @Test%0A
@@ -1222,32 +1222,40 @@
 %0A    %0A  @Test%0A  
+@Ignore%0A
   public void in
@@ -1259,17 +1259,16 @@
  include
-d
 BasicFlo
@@ -1272,24 +1272,30 @@
 Flow
-CanBeRunOnItsOwn
+TwoNonConsecutiveTimes
 () %7B
@@ -1678,32 +1678,148 @@
 LUDED_USE_CASE)%0A
+            .step(SYSTEM_DISPLAYS_TEXT_AGAIN).system(displayConstantText())%0A            .include(INCLUDED_USE_CASE)%0A
         .build()
@@ -1823,26 +1823,24 @@
 d();%0A      %0A
-  
     useCaseM
@@ -1873,18 +1873,16 @@
 l);%0A    
-  
 useCaseM
@@ -1896,24 +1896,52 @@
 ner.reactTo(
+enterText(), enterNumber(), 
 enterNumber(
@@ -1944,25 +1944,837 @@
 ber());%0A
+%0A
     
-  %0A  
+String expectedSteps =%0A        SYSTEM_DISPLAYS_TEXT + %22;%22%0A            + SYSTEM_DISPLAYS_NUMBER + %22;%22%0A            + SYSTEM_DISPLAYS_TEXT_AGAIN + %22;%22%0A            + SYSTEM_DISPLAYS_NUMBER + %22;%22;%0A    assertEquals(expectedSteps, runStepNames());%0A  %7D%0A    %0A  @Test%0A  public void includedBasicFlowCanBeRunOnItsOwn() %7B%0A      UseCaseModel useCaseModel = useCaseModelBuilder%0A        .useCase(INCLUDED_USE_CASE)%0A          .basicFlow()%0A            .step(SYSTEM_DISPLAYS_NUMBER).user(EnterNumber.class).system(displayEnteredNumber())%0A        .useCase(USE_CASE)%0A          .basicFlow()%0A            .step(SYSTEM_DISPLAYS_TEXT).user(EnterText.class).system(displayEnteredText())%0A            .include(INCLUDED_USE_CASE)%0A        .build();%0A      %0A    useCaseModelRunner.run(useCaseModel);%0A    useCaseModelRunner.reactTo(enterNumber());%0A%0A
     asse
@@ -2825,20 +2825,18 @@
 epNames());%0A
-  
   %7D%0A%7D%0A

Refactor IncludeTest