@@ -0,0 +1,3003 @@
+package com.tngtech.jgiven.junit;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat;%0A%0Aimport com.tngtech.jgiven.Stage;%0Aimport com.tngtech.jgiven.annotation.AfterStage;%0Aimport com.tngtech.jgiven.annotation.BeforeStage;%0Aimport com.tngtech.jgiven.annotation.ScenarioStage;%0Aimport org.junit.Ignore;%0Aimport org.junit.Test;%0A%0Apublic class SimpleStageRepetitionUseTest%0A    extends SimpleScenarioTest%3CSimpleStageRepetitionUseTest.RepeatLifecycleMethods%3E %7B%0A%0A    @ScenarioStage%0A    DontRepeatLifecycleMethods dontRepeatLifecycleMethods;%0A%0A    /* FIXME:%0A    We use the change of a stage class to detect that there is a new stage.%0A    Hence, repeatedly using the same stage does not work!%0A    */%0A    @Test%0A    @Ignore(%22Feature not implemented yet%22)%0A    public void lifecycle_methods_of_a_shared_stage_are_called_individually() %7B%0A        given().a_simple_stage_containing_before_and_after_methods();%0A        when().the_test_is_executed();%0A        then().the_before_stage_was_called_$_times(3).and()%0A            .the_after_stage_method_was_called_$_times(2); //we assert before the last call to 'afterStage'%0A    %7D%0A%0A    @Test%0A    public void non_repeatable_methods_are_called_exactly_once() %7B%0A        dontRepeatLifecycleMethods.given().a_simple_stage_containing_before_and_after_methods();%0A        dontRepeatLifecycleMethods.when().the_test_is_executed();%0A        dontRepeatLifecycleMethods.then().the_before_stage_was_called_$_times(1).and()%0A            .the_after_stage_method_was_called_$_times(0);%0A    %7D%0A%0A    static class DontRepeatLifecycleMethods extends AllTestSteps%3CDontRepeatLifecycleMethods%3E %7B%0A        @BeforeStage%0A        protected void beforeStage() %7B%0A            callBeforeStage();%0A        %7D%0A%0A        @AfterStage%0A        protected void afterStage() %7B%0A            callAfterStage();%0A        %7D%0A    %7D%0A%0A    static class RepeatLifecycleMethods extends AllTestSteps%3CRepeatLifecycleMethods%3E %7B%0A        @BeforeStage(repeatable = true)%0A        protected void beforeStage() %7B%0A            callBeforeStage();%0A        %7D%0A%0A        @AfterStage(repeatable = true)%0A        protected void afterStage() %7B%0A            callAfterStage();%0A        %7D%0A    %7D%0A%0A    static class AllTestSteps%3CT extends AllTestSteps%3C?%3E%3E extends Stage%3CT%3E %7B%0A%0A        private int beforeStageCalled = 0;%0A        private int afterStageCalled = 0;%0A%0A        protected void callBeforeStage() %7B%0A            beforeStageCalled++;%0A        %7D%0A%0A        protected void callAfterStage() %7B%0A            afterStageCalled++;%0A        %7D%0A%0A        T a_simple_stage_containing_before_and_after_methods() %7B%0A            return self();%0A        %7D%0A%0A        T the_test_is_executed() %7B%0A            return self();%0A        %7D%0A%0A        T the_after_stage_method_was_called_$_times(int numberOfCalls) %7B%0A            assertThat(afterStageCalled).isEqualTo(numberOfCalls);%0A            return self();%0A        %7D%0A%0A        T the_before_stage_was_called_$_times(int numberOfCalls) %7B%0A            assertThat(beforeStageCalled).isEqualTo(numberOfCalls);%0A            return self();%0A        %7D%0A    %7D%0A%7D%0A

Test repeatable after stage methods when used in two consecutive stages