package helloworld;

import java.util.Scanner;
import java.util.function.Consumer;

import org.requirementsascode.Actor;
import org.requirementsascode.UseCaseModel;
import org.requirementsascode.UseCaseModelRun;

public class HelloWorld02_UserEntersName {
	public static void main(String[] args) {
		UseCaseModelRun useCaseModelRun = new UseCaseModelRun();
		UseCaseModel useCaseModel = useCaseModelRun.getModel();
		
		Actor user = useCaseModel.newActor("User");
		
		useCaseModel.newUseCase("Get greeted")
			.basicFlow()
				.newStep("User enters first name. System greets user with first name.")
					.actor(user, EnterFirstName.class)
					.system(greetUser());
		
		useCaseModelRun.as(user);
		useCaseModelRun.reactTo(enterFirstNameEvent());
	}
	
	private static EnterFirstName enterFirstNameEvent() {
		System.out.print("Please enter your first name: ");
		Scanner scanner = new Scanner(System.in);
		String firstName = scanner.next();
		scanner.close();
		return new EnterFirstName(firstName);
	}
	
	private static Consumer<EnterFirstName> greetUser() {
		return event -> System.out.println("Hello, " + event.getFirstName() + ".");
	}
	
	private static class EnterFirstName {
		private String firstName;
		public EnterFirstName(String firstName) {
			this.firstName = firstName;
		}
		public String getFirstName() {
			return firstName;
		}
	}
}

@@ -801,16 +801,159 @@
 ent() %7B%0A
+%09%09String firstName = enterFirstNameInConsole();%0A%09%09return new EnterFirstName(firstName);%0A%09%7D%0A%0A%09private static String enterFirstNameInConsole() %7B%0A
 %09%09System
@@ -1107,35 +1107,16 @@
 %09return 
-new EnterFirstName(
 firstNam
@@ -1112,25 +1112,24 @@
 rn firstName
-)
 ;%0A%09%7D%0A%09%0A%09priv

Refactor HelloWorld02