package org.requirementsascode;

import java.util.Objects;

public class RecordingActor extends AbstractActor {
  private AbstractActor baseActor;

  private RecordingActor(AbstractActor baseActor) {
    this.baseActor = Objects.requireNonNull(baseActor);
    baseActor.getModelRunner().startRecording();
  }

  /**
   * Creates an actor that records the steps and messages that are handled
   * by the specified base actor.
   * 
   * @param baseActor the actor whose steps and messages to record
   * @return an actor ready for recording
   */
  public static RecordingActor basedOn(AbstractActor baseActor) {
    return new RecordingActor(baseActor);
  }

  @Override
  public ModelRunner getModelRunner() {
    return baseActor.getModelRunner();
  }

  @Override
  public Model behavior() {
    return baseActor.behavior();
  }

  /**
   * Returns the names of steps that have been run, since the creation of this
   * actor.
   * 
   * @return the step names
   */
  public String[] getRecordedStepNames() {
    String[] recordedStepNames = getModelRunner().getRecordedStepNames();
    return recordedStepNames;
  }

  /**
   * Returns the messages that caused a step to run, since the creation of this
   * actor.
   * 
   * @return the messages
   */
  public Object[] getRecordedMessages() {
    Object[] recordedMessages = getModelRunner().getRecordedMessages();
    return recordedMessages;
  }
}

@@ -26,16 +26,67 @@
 scode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A
 import j
@@ -170,196 +170,949 @@
 ate 
-AbstractActor baseActor;%0A%0A  private RecordingActor(AbstractActor baseActor) %7B%0A    this.baseActor = Objects.requireNonNull(baseActor);%0A    baseActor.getModelRunner().startRecording(
+static final Class%3C?%3E SYSTEM_EVENT_CLASS = ModelRunner.class;%0A  %0A  private final AbstractActor baseActor;%0A  private final List%3CString%3E recordedStepNames;%0A  private final List%3CObject%3E recordedMessages;%0A%0A  private RecordingActor(AbstractActor baseActor) %7B%0A    this.baseActor = Objects.requireNonNull(baseActor, %22baseActor must be non-null!%22);%0A    getModelRunner().handleWith(stepToBeRun -%3E %7B%0A      recordStepNameAndMessage(stepToBeRun.getStepName(), stepToBeRun.getMessage().orElse(null));%0A      stepToBeRun.run();%0A    %7D);%0A    recordedStepNames = new ArrayList%3C%3E();%0A    recordedMessages = new ArrayList%3C%3E();%0A  %7D%0A  %0A  private void recordStepNameAndMessage(String stepName, Object message) %7B%0A    recordedStepNames.add(stepName);%0A    if (message != null && !isSystemEvent(message)) %7B%0A      recordedMessages.add(message);%0A    %7D%0A  %7D%0A  %0A  private %3CT%3E boolean isSystemEvent(T message) %7B%0A    return SYSTEM_EVENT_CLASS.equals(message.getClass()
 );%0A  %7D%0A%0A
   /*
@@ -1099,32 +1099,33 @@
 tClass());%0A  %7D%0A%0A
+%0A
   /**%0A   * Creat
@@ -1824,25 +1824,17 @@
 tring%5B%5D 
-recordedS
+s
 tepNames
@@ -1840,46 +1840,56 @@
 s = 
-getModelRunner().getRecordedStepNames(
+recordedStepNames.stream().toArray(String%5B%5D::new
 );%0A 
@@ -1898,25 +1898,17 @@
  return 
-recordedS
+s
 tepNames
@@ -2105,25 +2105,17 @@
 bject%5B%5D 
-recordedM
+m
 essages 
@@ -2120,29 +2120,9 @@
 s = 
-getModelRunner().getR
+r
 ecor
@@ -2132,16 +2132,24 @@
 Messages
+.toArray
 ();%0A    
@@ -2155,25 +2155,17 @@
  return 
-recordedM
+m
 essages;

Remove some dependencies on ModelRunner