public Model buildWith(ModelBuilder modelBuilder) { Model model = modelBuilder.useCase("Get greeted") .basicFlow() .step("S1").system(this::promptsUserToEnterFirstName) .step("S2").user(ENTERS_FIRST_NAME).system(this::savesFirstName) .step("S3").system(this::promptsUserToEnterAge) .step("S4").user(ENTERS_AGE).system(this::savesAge) .step("S5").system(this::greetsUserWithFirstNameAndAge) .build(); return model; }
public Model buildWith(ModelBuilder modelBuilder) { Model model = modelBuilder.useCase("Feel Stuff") .basicFlow() .step("1").user(asksForPoem).system(feelStuffUseCaseRealization::writesSadPoem) .step("2").user(asksForPoem).system(feelStuffUseCaseRealization::writesHappyPoem) .step("3").user(asksForPoem).system(feelStuffUseCaseRealization::writesFunnyPoem) .build(); return model; } }
public void start() { ModelBuilder modelBuilder = Model.builder(); Model model = modelBuilder.useCase("Measure performance of simple mathematical operations") .basicFlow() .step("S1").system(this::addsTwoNumbers) .step("S2").system(this::calculatesTwoToThePowerOfAThousand) .step("S3").system(this::displaysResults).build(); ModelRunner modelRunner = new ModelRunner(); modelRunner.handleWith(this::measuresPerformance); modelRunner.run(model); }
public Model buildWith(ModelBuilder modelBuilder) { Model model = modelBuilder.useCase("Get greeted") .basicFlow() .step("S1").system(this::greetsUser) .step("S2").system(this::printsHooray).reactWhile(this::lessThanThreeHooraysHaveBeenPrinted) .build(); return model; }
public Model buildWith(ModelBuilder modelBuilder) { Model model = modelBuilder.useCase("Get greeted") .basicFlow() .step("S1").system(this::promptsUserToEnterFirstName) .step("S2").user(ENTERS_FIRST_NAME).system(this::greetsUserWithFirstName) .build(); return model; }
static Model model() { SaysHelloWorld saysHelloWorld = new SaysHelloWorld(); SaysHelloToUser saysHelloToUser = new SaysHelloToUser(); Model model = Model.builder().useCase("Say hello to world, then user") .basicFlow() .step("S1").user(ASKS_FOR_HELLO_WORLD).system(saysHelloWorld) .step("S2").user(ASKS_FOR_HELLO_TO_USER).system(saysHelloToUser) .build(); return model; }
@Test public void createsTwoStepsInBasicFlowAndCheckIfTheyExistByIndex() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); useCasePart.basicFlow() .step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()) .step(SYSTEM_DISPLAYS_TEXT_AGAIN).system(displaysConstantText()); List<FlowStep> steps = useCasePart.getUseCase().getBasicFlow().getSteps(); assertEquals(2, steps.size()); assertEquals(SYSTEM_DISPLAYS_TEXT, steps.get(0).getName()); assertEquals(SYSTEM_DISPLAYS_TEXT_AGAIN, steps.get(1).getName()); }
@Test public void createsTwoStepsAndPreviousStepOfSecondOneIsFirstOne() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); useCasePart.basicFlow() .step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()) .step(SYSTEM_DISPLAYS_TEXT_AGAIN).system(displaysConstantText()); FlowStep firstUseCaseStep = (FlowStep)useCasePart.getUseCase().findStep(SYSTEM_DISPLAYS_TEXT); FlowStep secondUseCaseStep = (FlowStep)useCasePart.getUseCase().findStep(SYSTEM_DISPLAYS_TEXT_AGAIN); assertEquals(firstUseCaseStep, secondUseCaseStep.getPreviousStepInFlow().get()); }
@Test public void throwsExceptionIfStepIsCreatedTwice() { thrown.expect(ElementAlreadyInModel.class); thrown.expectMessage(CUSTOMER_ENTERS_TEXT); modelBuilder .useCase(USE_CASE) .basicFlow() .step(CUSTOMER_ENTERS_TEXT).system(displaysConstantText()) .step(CUSTOMER_ENTERS_TEXT).system(displaysConstantText()); }
@Test public void printsTextAutonomouslyTwice() { Model model = modelBuilder .useCase(USE_CASE) .basicFlow() .step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()) .step(SYSTEM_DISPLAYS_TEXT_AGAIN).system(displaysConstantText()) .build(); modelRunner.run(model); assertRecordedStepNames(SYSTEM_DISPLAYS_TEXT, SYSTEM_DISPLAYS_TEXT_AGAIN); }
@Test public void createsTwoStepsAndCheckIfTheyExistInUseCaseByName() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); useCasePart.basicFlow() .step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()) .step(SYSTEM_DISPLAYS_TEXT_AGAIN).system(displaysConstantText()); Collection<Step> steps = useCasePart.getUseCase().getSteps(); assertEquals(2, steps.size()); boolean firstUseCaseStepExists = useCasePart.getUseCase().hasStep(SYSTEM_DISPLAYS_TEXT); boolean secondUseCaseStepExists = useCasePart.getUseCase().hasStep(SYSTEM_DISPLAYS_TEXT_AGAIN); assertTrue(firstUseCaseStepExists); assertTrue(secondUseCaseStepExists); }
@Test public void printsTextAutonomouslyOnlyIfActorIsRightInSecondStep() { Model model = modelBuilder .useCase(USE_CASE) .basicFlow() .step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()) .step(SYSTEM_DISPLAYS_TEXT_AGAIN).as(customer).system(displaysConstantText()) .build(); modelRunner.as(customer).run(model); assertRecordedStepNames(SYSTEM_DISPLAYS_TEXT, SYSTEM_DISPLAYS_TEXT_AGAIN); }
@Test public void printsTextAutonomouslyOnlyIfActorIsRightInFirstStep() { Model model = modelBuilder .useCase(USE_CASE) .basicFlow() .step(SYSTEM_DISPLAYS_TEXT).as(customer).system(displaysConstantText()) .step(SYSTEM_DISPLAYS_TEXT_AGAIN).as(secondActor).system(displaysConstantText()) .build(); modelRunner.as(customer).run(model); assertRecordedStepNames(SYSTEM_DISPLAYS_TEXT); }
@Test public void twoSequentialStepsReactToEventsOfDifferentType() { Model model = modelBuilder .useCase(USE_CASE) .basicFlow() .step(CUSTOMER_ENTERS_TEXT).user(EntersText.class).system(displaysEnteredText()) .step(CUSTOMER_ENTERS_NUMBER).user(EntersNumber.class).system(displaysEnteredNumber()) .build(); modelRunner.run(model); reactToAndAssertEvents(entersText(), entersNumber()); }
@Test public void twoSequentialStepsReactToEventsOfSameType() { Model model = modelBuilder .useCase(USE_CASE) .basicFlow() .step(CUSTOMER_ENTERS_TEXT).user(EntersText.class).system(displaysEnteredText()) .step(CUSTOMER_ENTERS_TEXT_AGAIN).user(EntersText.class).system(displaysEnteredText()) .build(); modelRunner.run(model); reactToAndAssertEvents(entersText(), entersText()); }
@Test public void twoSequentialStepsReactWhenSeveralActorsContainRightActorAtFirstPosition() { Model model = modelBuilder .useCase(USE_CASE) .basicFlow() .step(CUSTOMER_ENTERS_TEXT) .as(customer).user(EntersText.class).system(displaysEnteredText()) .step(CUSTOMER_ENTERS_TEXT_AGAIN) .as(customer, secondActor).user(EntersText.class).system(displaysEnteredText()) .build(); modelRunner.as(customer).run(model); reactToAndAssertEvents(entersText(), entersText()); }
@Test public void twoSequentialStepsReactWhenSeveralActorsContainRightActorAtSecondPosition() { Model model = modelBuilder .useCase(USE_CASE) .basicFlow() .step(CUSTOMER_ENTERS_TEXT) .as(customer).user(EntersText.class).system(displaysEnteredText()) .step(CUSTOMER_ENTERS_TEXT_AGAIN) .as(secondActor, customer).user(EntersText.class).system(displaysEnteredText()) .build(); modelRunner.as(customer).run(model); reactToAndAssertEvents(entersText(), entersText()); }
@Test public void onlyStepWithRightActorReacts() { Model model = modelBuilder .useCase(USE_CASE) .basicFlow() .step(CUSTOMER_ENTERS_TEXT) .as(customer).user(EntersText.class).system(displaysEnteredText()) .step(CUSTOMER_ENTERS_TEXT_AGAIN) .as(secondActor).user(EntersText.class).system(throwsRuntimeException()) .build(); modelRunner.as(customer).run(model).reactTo(entersText(), entersText()); assertRecordedStepNames(CUSTOMER_ENTERS_TEXT); }
@Test public void reactsToFirstStepAlternativeWhen() { Model model = modelBuilder .useCase(USE_CASE) .basicFlow() .step(THIS_STEP_SHOULD_BE_SKIPPED).user(EntersText.class).system(throwsRuntimeException()) .step(THIS_STEP_SHOULD_BE_SKIPPED_AS_WELL).user(EntersText.class).system(throwsRuntimeException()) .flow(ALTERNATIVE_FLOW).condition(this::textIsNotAvailable) .step(CUSTOMER_ENTERS_ALTERNATIVE_TEXT).user(EntersText.class).system(displaysEnteredText()) .build(); modelRunner.run(model).reactTo(entersText()); assertRecordedStepNames(CUSTOMER_ENTERS_ALTERNATIVE_TEXT); }
@Test public void reactsToAlternativeAfterFirstStep() { Model model = modelBuilder .useCase(USE_CASE) .basicFlow() .step(CUSTOMER_ENTERS_TEXT).user(EntersText.class).system(displaysEnteredText()) .step(THIS_STEP_SHOULD_BE_SKIPPED).user(EntersText.class).system(throwsRuntimeException()) .flow(ALTERNATIVE_FLOW).insteadOf(THIS_STEP_SHOULD_BE_SKIPPED) .step(CUSTOMER_ENTERS_ALTERNATIVE_TEXT).user(EntersText.class).system(displaysEnteredText()) .build(); modelRunner.run(model).reactTo(entersText(), entersAlternativeText()); assertRecordedStepNames(CUSTOMER_ENTERS_TEXT, CUSTOMER_ENTERS_ALTERNATIVE_TEXT); }