package pizzavolumecalculator.actor;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

import java.util.Optional;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.requirementsascode.AbstractActor;

import pizzavolumecalculator.actor.command.CalculateVolume;
import pizzavolumecalculator.actor.command.EnterHeight;
import pizzavolumecalculator.actor.command.EnterRadius;

public class PizzaVolumeCalculatorTest {
  private AbstractActor calculator;

  @Rule
  public ExpectedException thrown = ExpectedException.none();

  @Before
  public void setup() {
    calculator = new PizzaVolumeCalculator();
    calculator.getModelRunner().startRecording();
  }

	@Test
	public void testBasicFlow() {
	  calculator.reactTo(new EnterRadius(4));
	  calculator.reactTo(new EnterHeight(5));
	  Optional<Double> pizzaVolume = calculator.reactTo(new CalculateVolume());
		assertRecordedStepNames("S1", "S2", "S3", "S4");
		
		assertEquals(251.327, pizzaVolume.get(), 0.01);
	}
	
  @Test
  public void testBasicFlowTwice() {
    calculator.reactTo(new EnterRadius(2));
    calculator.reactTo(new EnterHeight(3));
    Optional<Double> pizzaVolume = calculator.reactTo(new CalculateVolume());
    
    assertEquals(37.69, pizzaVolume.get(), 0.01);

    calculator.reactTo(new EnterRadius(4));
    calculator.reactTo(new EnterHeight(5));
    pizzaVolume = calculator.reactTo(new CalculateVolume());
    assertRecordedStepNames("S1", "S2", "S3", "S4", "S1", "S2", "S3", "S4");

    assertEquals(251.32, pizzaVolume.get(), 0.01);
  }

  @Test
  public void testIllegalRadius() {
    thrown.expect(IllegalArgumentException.class);
    calculator.reactTo(new EnterRadius(-1));
  }

  @Test
  public void testIllegalHeight() {
    thrown.expect(IllegalArgumentException.class);
    calculator.reactTo(new EnterRadius(5));
    calculator.reactTo(new EnterHeight(-1));
  }

  protected void assertRecordedStepNames(String... expectedStepNames) {
    String[] actualStepNames = calculator.getModelRunner().getRecordedStepNames();
    assertArrayEquals(expectedStepNames, actualStepNames);
  }
}

@@ -552,17 +552,28 @@
 ctActor 
-c
+pizzaVolumeC
 alculato
@@ -677,33 +677,44 @@
 d setup() %7B%0A    
-c
+pizzaVolumeC
 alculator = new 
@@ -738,25 +738,36 @@
 ator();%0A    
-c
+pizzaVolumeC
 alculator.ge
@@ -841,25 +841,36 @@
 Flow() %7B%0A%09  
-c
+pizzaVolumeC
 alculator.re
@@ -899,17 +899,28 @@
 4));%0A%09  
-c
+pizzaVolumeC
 alculato
@@ -976,33 +976,44 @@
 %3E pizzaVolume = 
-c
+pizzaVolumeC
 alculator.reactT
@@ -1192,25 +1192,36 @@
 ice() %7B%0A    
-c
+pizzaVolumeC
 alculator.re
@@ -1243,33 +1243,44 @@
 Radius(2));%0A    
-c
+pizzaVolumeC
 alculator.reactT
@@ -1329,33 +1329,44 @@
 %3E pizzaVolume = 
-c
+pizzaVolumeC
 alculator.reactT
@@ -1447,25 +1447,36 @@
 0.01);%0A%0A    
-c
+pizzaVolumeC
 alculator.re
@@ -1498,33 +1498,44 @@
 Radius(4));%0A    
-c
+pizzaVolumeC
 alculator.reactT
@@ -1575,17 +1575,28 @@
 olume = 
-c
+pizzaVolumeC
 alculato
@@ -1854,33 +1854,44 @@
 ion.class);%0A    
-c
+pizzaVolumeC
 alculator.reactT
@@ -2014,25 +2014,36 @@
 class);%0A    
-c
+pizzaVolumeC
 alculator.re
@@ -2073,17 +2073,28 @@
 ));%0A    
-c
+pizzaVolumeC
 alculato
@@ -2233,17 +2233,28 @@
 Names = 
-c
+pizzaVolumeC
 alculato

Rename refactoring