package org.requirementsascode;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.Set;

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

public class CanReactToTest extends AbstractTestCase {

    @Before
    public void setup() {
	setupWithRecordingModelRunner();
    }

    @Test
    public void cantReactIfNotRunning() {
	boolean canReact = modelRunner.canReactTo(entersText().getClass());
	assertFalse(canReact);
    }

    @Test
    public void cantReactIfEventIsWrong() {
	Model model = modelBuilder.useCase(USE_CASE)
		.basicFlow()
			.step(CUSTOMER_ENTERS_TEXT).user(EntersText.class).system(displaysEnteredText())
	.build();

	modelRunner.run(model);

	boolean canReact = modelRunner.canReactTo(entersNumber().getClass());
	assertFalse(canReact);
    }
    

    @Test
    public void oneStepCanReactIfEventIsRight() {
	Model model = modelBuilder.useCase(USE_CASE)
		.basicFlow()
			.step(CUSTOMER_ENTERS_TEXT).user(EntersText.class).system(displaysEnteredText()).build();

	modelRunner.run(model);

	boolean canReact = modelRunner.canReactTo(entersText().getClass());
	assertTrue(canReact);

	Set<Step> stepsThatCanReact = modelRunner.getStepsThatCanReactTo(entersText().getClass());
	assertEquals(1, stepsThatCanReact.size());
	assertEquals(CUSTOMER_ENTERS_TEXT, stepsThatCanReact.iterator().next().getName().toString());
    }

    @Test
    public void moreThanOneStepCanReact() {
	Model model = modelBuilder.useCase(USE_CASE)
		.basicFlow().anytime()
			.step(CUSTOMER_ENTERS_TEXT).user(EntersText.class).system(displaysEnteredText())
		.flow("Alternative Flow: Could react as well").anytime()
			.step(CUSTOMER_ENTERS_ALTERNATIVE_TEXT).user(EntersText.class).system(displaysEnteredText())
		.build();

	modelRunner.run(model);

	boolean canReact = modelRunner.canReactTo(entersText().getClass());
	assertTrue(canReact);

	Set<Step> stepsThatCanReact = modelRunner.getStepsThatCanReactTo(entersText().getClass());
	assertEquals(2, stepsThatCanReact.size());
    }
}

@@ -418,16 +418,17 @@
 ing() %7B%0A
+%09
 %09boolean
@@ -480,32 +480,33 @@
 ().getClass());%0A
+%09
 %09assertFalse(can
@@ -570,24 +570,25 @@
 IsWrong() %7B%0A
+%09
 %09Model model
@@ -613,32 +613,33 @@
 eCase(USE_CASE)%0A
+%09
 %09%09.basicFlow()%0A%09
@@ -632,32 +632,33 @@
 .basicFlow()%0A%09%09%09
+%09
 .step(CUSTOMER_E
@@ -722,16 +722,17 @@
 Text())%0A
+%09
 %09.build(
@@ -726,33 +726,35 @@
 ())%0A%09%09.build();%0A
+%09
 %0A
+%09
 %09modelRunner.run
@@ -754,33 +754,35 @@
 ner.run(model);%0A
-%0A
+%09%0A%09
 %09boolean canReac
@@ -832,24 +832,25 @@
 etClass());%0A
+%09
 %09assertFalse
@@ -871,16 +871,382 @@
   %7D%0A    
+%0A    @Test%0A    public void cantReactIfConditionIsWrong() %7B%0A%09%09Model model = modelBuilder.useCase(USE_CASE)%0A%09%09%09.basicFlow().condition(() -%3E false)%0A%09%09%09%09.step(CUSTOMER_ENTERS_TEXT).user(EntersText.class).system(displaysEnteredText()).build();%0A%09%0A%09%09modelRunner.run(model);%0A%09%0A%09%09boolean canReact = modelRunner.canReactTo(entersText().getClass());%0A%09%09assertFalse(canReact);%0A%09%7D
 %0A%0A    @T
@@ -1295,24 +1295,25 @@
 IsRight() %7B%0A
+%09
 %09Model model
@@ -1340,32 +1340,33 @@
 ase(USE_CASE)%0A%09%09
+%09
 .basicFlow()%0A%09%09%09
@@ -1362,16 +1362,17 @@
 cFlow()%0A
+%09
 %09%09%09.step
@@ -1448,33 +1448,35 @@
 ext()).build();%0A
-%0A
+%09%0A%09
 %09modelRunner.run
@@ -1476,33 +1476,35 @@
 ner.run(model);%0A
+%09
 %0A
+%09
 %09boolean canReac
@@ -1548,32 +1548,33 @@
 ().getClass());%0A
+%09
 %09assertTrue(canR
@@ -1572,33 +1572,35 @@
 True(canReact);%0A
+%09
 %0A
+%09
 %09Set%3CStep%3E steps
@@ -1667,32 +1667,33 @@
 ().getClass());%0A
+%09
 %09assertEquals(1,
@@ -1716,24 +1716,25 @@
 ct.size());%0A
+%09
 %09assertEqual

Add test for false condition