package pizzavolumecalculator.actor;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Optional;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.requirementsascode.RecordingActor;

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

public class PizzaVolumeCalculatorTest {
  private RecordingActor pizzaVolumeCalculator;

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

  @BeforeEach
  public void setup() {
    pizzaVolumeCalculator = 
      RecordingActor.basedOn(new PizzaVolumeCalculator());
  }

  @Test
  public void testBasicFlow() {
    pizzaVolumeCalculator.reactTo(new EnterRadius(4));
    pizzaVolumeCalculator.reactTo(new EnterHeight(5));
    Optional<Double> pizzaVolume = pizzaVolumeCalculator.reactTo(new CalculateVolume());
    assertRecordedStepNames("S1", "S2", "S3", "S4"); 

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

  @Test
  public void testBasicFlowTwice() {
    reactAndAssertMessagesAreHandled(new EnterRadius(2), new EnterHeight(3), new CalculateVolume(),
      new EnterRadius(4), new EnterHeight(5));
    Optional<Double> pizzaVolume = pizzaVolumeCalculator.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);
    pizzaVolumeCalculator.reactTo(new EnterRadius(-1));
  }

  @Test
  public void testIllegalHeight() {
    thrown.expect(IllegalArgumentException.class);
    pizzaVolumeCalculator.reactTo(new EnterRadius(5));
    pizzaVolumeCalculator.reactTo(new EnterHeight(-1));
  }
  
  protected void reactAndAssertMessagesAreHandled(Object... messages) {
    pizzaVolumeCalculator.reactTo(messages);
    final Object[] actualMessages = pizzaVolumeCalculator.getRecordedMessages();
    assertArrayEquals(messages, actualMessages);
  }

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

@@ -157,16 +157,77 @@
 tEquals;
+%0Aimport static org.junit.jupiter.api.Assertions.assertThrows;
 %0A%0Aimport
@@ -638,79 +638,8 @@
 r;%0A%0A
-  @Rule%0A  public ExpectedException thrown = ExpectedException.none();%0A%0A
   @B
@@ -1575,37 +1575,36 @@
 ius() %7B%0A    
-thrown.expect
+assertThrows
 (IllegalArgu
@@ -1614,35 +1614,44 @@
 tException.class
-);%0A
+, () -%3E %7B%0A  
     pizzaVolumeC
@@ -1686,24 +1686,32 @@
 adius(-1));%0A
+    %7D);%0A
   %7D%0A%0A  @Test
@@ -1755,21 +1755,20 @@
     
-thrown.expect
+assertThrows
 (Ill
@@ -1794,19 +1794,28 @@
 on.class
-);%0A
+, () -%3E %7B%0A  
     pizz
@@ -1857,24 +1857,26 @@
 Radius(5));%0A
+  
     pizzaVol
@@ -1915,24 +1915,32 @@
 eight(-1));%0A
+    %7D);%0A
   %7D%0A  %0A  pro

Move exception tests to JUnit 5