@Test public void throwsExceptionIfAfterStepNotExistsInSameUseCase() { thrown.expect(NoSuchElementInModel.class); thrown.expectMessage(CUSTOMER_ENTERS_TEXT); modelBuilder.useCase(USE_CASE).basicFlow().after(CUSTOMER_ENTERS_TEXT); }
@Test public void eventTypesReactedOnlyIfFlowPositionIsRight() { Model model = modelBuilder.useCase(USE_CASE) .basicFlow() .step(CUSTOMER_ENTERS_TEXT).user(EntersText.class).system(displaysEnteredText()) .flow("Alternative Flow: Could react as well").after(CUSTOMER_ENTERS_TEXT) .step(CUSTOMER_ENTERS_NUMBER).user(EntersNumber.class).system(displaysEnteredNumber()) .build(); modelRunner.run(model); Set<Class<?>> reactToTypes = modelRunner.getReactToTypes(); assertEquals(1, reactToTypes.size()); Class<?> eventTypeReactedTo = reactToTypes.iterator().next(); assertEquals(EntersText.class, eventTypeReactedTo); modelRunner.reactTo(entersText()); reactToTypes = modelRunner.getReactToTypes(); assertEquals(1, reactToTypes.size()); eventTypeReactedTo = reactToTypes.iterator().next(); assertEquals(EntersNumber.class, eventTypeReactedTo); } }
@Test public void doesNotHandleExceptionIfNoExceptionOccurs() { Model model = modelBuilder.useCase(USE_CASE) .basicFlow() .step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()) .flow(ALTERNATIVE_FLOW).after(SYSTEM_DISPLAYS_TEXT) .step(SYSTEM_HANDLES_EXCEPTION).on(ArrayIndexOutOfBoundsException.class).system(e -> {}) .build(); modelRunner.run(model); assertRecordedStepNames(SYSTEM_DISPLAYS_TEXT); }
@Test public void doesNotHandleExceptionIfSystemReactionDoesNotThrowException() { Model model = modelBuilder.useCase(USE_CASE) .basicFlow() .step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()) .flow(ALTERNATIVE_FLOW).after(SYSTEM_DISPLAYS_TEXT) .step(SYSTEM_HANDLES_EXCEPTION).on(ArrayIndexOutOfBoundsException.class).system(e -> {}) .build(); modelRunner.run(model); assertRecordedStepNames(SYSTEM_DISPLAYS_TEXT); }
@Test public void handlesExceptionAfterSpecificStep() { Model model = modelBuilder.useCase(USE_CASE) .basicFlow() .step(SYSTEM_THROWS_EXCEPTION).system(throwsArrayIndexOutOfBoundsException()) .flow(ALTERNATIVE_FLOW).after(SYSTEM_THROWS_EXCEPTION) .step(SYSTEM_HANDLES_EXCEPTION).on(ArrayIndexOutOfBoundsException.class).system(e -> {}) .build(); modelRunner.run(model); assertEquals(SYSTEM_HANDLES_EXCEPTION, latestStepName()); }
@Test public void handlesExceptionAtAnyTime() { Model model = modelBuilder.useCase(USE_CASE) .basicFlow() .step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()) .flow(ALTERNATIVE_FLOW).after(SYSTEM_DISPLAYS_TEXT) .step(SYSTEM_THROWS_EXCEPTION).system(throwsArrayIndexOutOfBoundsException()) .flow(ALTERNATIVE_FLOW_2).anytime() .step(SYSTEM_HANDLES_EXCEPTION).on(ArrayIndexOutOfBoundsException.class).system(e -> {}) .build(); modelRunner.run(model); assertRecordedStepNames(SYSTEM_DISPLAYS_TEXT, SYSTEM_THROWS_EXCEPTION, SYSTEM_HANDLES_EXCEPTION); } }
.step("S4a_1").system(blowsUp()) .step("S4a_2").continuesAt("S1") .flow("Alternative flow B").after("S3") .step("S4b_1").continuesAfter("S2") .flow("Alternative flow C").condition(thereIsNoAlternative())