diff --git a/build.gradle b/build.gradle index b8456ac7..0742229c 100644 --- a/build.gradle +++ b/build.gradle @@ -271,10 +271,10 @@ project('spring-statemachine-test') { compile 'org.springframework:spring-test' compile 'org.hamcrest:hamcrest-core' compile 'org.hamcrest:hamcrest-library' - compile 'junit:junit' - compile 'org.junit.jupiter:junit-jupiter-api' - compile 'org.junit.vintage:junit-vintage-engine' compile 'org.assertj:assertj-core' + optional 'junit:junit' + optional 'org.junit.jupiter:junit-jupiter-api' + optional 'org.junit.vintage:junit-vintage-engine' testCompile('org.mockito:mockito-core') { dep -> exclude group: 'org.hamcrest' } diff --git a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/EndSmokeTests.java b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/EndSmokeTests.java index fe2d6561..cc649ccd 100644 --- a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/EndSmokeTests.java +++ b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/EndSmokeTests.java @@ -17,7 +17,7 @@ package org.springframework.statemachine.buildtests; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; diff --git a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/Gh737Tests.java b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/Gh737Tests.java index 4d2c036a..d48c87f3 100644 --- a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/Gh737Tests.java +++ b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/Gh737Tests.java @@ -16,10 +16,10 @@ package org.springframework.statemachine.buildtests; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.assertThat; import static org.springframework.statemachine.TestUtils.doSendEventAndConsumeAll; import static org.springframework.statemachine.TestUtils.doStartAndAssert; import static org.springframework.statemachine.TestUtils.resolveMachine; +import static org.hamcrest.MatcherAssert.assertThat; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; diff --git a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/LinkedRegionsTests.java b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/LinkedRegionsTests.java index 1120fb3c..d536ec9a 100644 --- a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/LinkedRegionsTests.java +++ b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/LinkedRegionsTests.java @@ -18,7 +18,7 @@ package org.springframework.statemachine.buildtests; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.ArrayList; diff --git a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/RedisPersistTests.java b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/RedisPersistTests.java index 5e0bf585..ea9298e5 100644 --- a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/RedisPersistTests.java +++ b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/RedisPersistTests.java @@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.springframework.statemachine.TestUtils.doSendEventAndConsumeAll; import static org.springframework.statemachine.TestUtils.doStartAndAssert; import static org.springframework.statemachine.TestUtils.resolveFactory; diff --git a/spring-statemachine-data/jpa/src/test/java/org/springframework/statemachine/data/jpa/JpaRepositoryTests.java b/spring-statemachine-data/jpa/src/test/java/org/springframework/statemachine/data/jpa/JpaRepositoryTests.java index 0f536ae7..ce4f2b71 100644 --- a/spring-statemachine-data/jpa/src/test/java/org/springframework/statemachine/data/jpa/JpaRepositoryTests.java +++ b/spring-statemachine-data/jpa/src/test/java/org/springframework/statemachine/data/jpa/JpaRepositoryTests.java @@ -17,7 +17,7 @@ package org.springframework.statemachine.data.jpa; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.springframework.statemachine.TestUtils.doSendEventAndConsumeAll; import static org.springframework.statemachine.TestUtils.doStartAndAssert; import static org.springframework.statemachine.TestUtils.resolveMachine; diff --git a/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/MongoDbRepositoryTests.java b/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/MongoDbRepositoryTests.java index 5587e1e8..cb4d4a1b 100644 --- a/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/MongoDbRepositoryTests.java +++ b/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/MongoDbRepositoryTests.java @@ -17,7 +17,7 @@ package org.springframework.statemachine.data.mongodb; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.springframework.statemachine.TestUtils.doSendEventAndConsumeAll; import static org.springframework.statemachine.TestUtils.doStartAndAssert; import static org.springframework.statemachine.TestUtils.resolveMachine; diff --git a/spring-statemachine-data/redis/src/test/java/org/springframework/statemachine/data/redis/RedisRepositoryTests.java b/spring-statemachine-data/redis/src/test/java/org/springframework/statemachine/data/redis/RedisRepositoryTests.java index 52ee867b..0b58b00a 100644 --- a/spring-statemachine-data/redis/src/test/java/org/springframework/statemachine/data/redis/RedisRepositoryTests.java +++ b/spring-statemachine-data/redis/src/test/java/org/springframework/statemachine/data/redis/RedisRepositoryTests.java @@ -17,7 +17,7 @@ package org.springframework.statemachine.data.redis; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.springframework.statemachine.TestUtils.doSendEventAndConsumeAll; import static org.springframework.statemachine.TestUtils.doStartAndAssert; import static org.springframework.statemachine.TestUtils.resolveMachine; diff --git a/spring-statemachine-data/src/test/java/org/springframework/statemachine/data/AbstractRepositoryTests.java b/spring-statemachine-data/src/test/java/org/springframework/statemachine/data/AbstractRepositoryTests.java index 399ef552..53d29091 100644 --- a/spring-statemachine-data/src/test/java/org/springframework/statemachine/data/AbstractRepositoryTests.java +++ b/spring-statemachine-data/src/test/java/org/springframework/statemachine/data/AbstractRepositoryTests.java @@ -17,7 +17,7 @@ package org.springframework.statemachine.data; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Iterator; diff --git a/spring-statemachine-test/src/main/java/org/springframework/statemachine/test/AbstractStateMachineTests.java b/spring-statemachine-test/src/main/java/org/springframework/statemachine/test/AbstractStateMachineJUnit4Tests.java similarity index 91% rename from spring-statemachine-test/src/main/java/org/springframework/statemachine/test/AbstractStateMachineTests.java rename to spring-statemachine-test/src/main/java/org/springframework/statemachine/test/AbstractStateMachineJUnit4Tests.java index f20da8c8..1a65c153 100644 --- a/spring-statemachine-test/src/main/java/org/springframework/statemachine/test/AbstractStateMachineTests.java +++ b/spring-statemachine-test/src/main/java/org/springframework/statemachine/test/AbstractStateMachineJUnit4Tests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext * @author Janne Valkealahti * */ -public abstract class AbstractStateMachineTests { +public abstract class AbstractStateMachineJUnit4Tests { protected AnnotationConfigApplicationContext context; diff --git a/spring-statemachine-test/src/main/java/org/springframework/statemachine/test/AbstractStateMachineJUnit5Tests.java b/spring-statemachine-test/src/main/java/org/springframework/statemachine/test/AbstractStateMachineJUnit5Tests.java new file mode 100644 index 00000000..6c3f57bf --- /dev/null +++ b/spring-statemachine-test/src/main/java/org/springframework/statemachine/test/AbstractStateMachineJUnit5Tests.java @@ -0,0 +1,53 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.statemachine.test; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +/** + * Base helper class for state machine tests. + * + * @author Janne Valkealahti + * + */ +public abstract class AbstractStateMachineJUnit5Tests { + + protected AnnotationConfigApplicationContext context; + + @BeforeEach + public void setup() { + context = buildContext(); + } + + @AfterEach + public void clean() { + if (context != null) { + context.close(); + } + } + + protected AnnotationConfigApplicationContext buildContext() { + return null; + } + + protected void registerAndRefresh(Class... annotatedClasses) { + context.register(annotatedClasses); + context.refresh(); + } + +} diff --git a/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestPlanBuilderTests.java b/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestPlanBuilderJUnit4Tests.java similarity index 93% rename from spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestPlanBuilderTests.java rename to spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestPlanBuilderJUnit4Tests.java index fbd7eef8..2066ec6c 100644 --- a/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestPlanBuilderTests.java +++ b/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestPlanBuilderJUnit4Tests.java @@ -17,14 +17,14 @@ package org.springframework.statemachine.test; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.List; import org.junit.Test; import org.springframework.statemachine.test.StateMachineTestPlanBuilder.StateMachineTestPlanStep; -public class StateMachineTestPlanBuilderTests { +public class StateMachineTestPlanBuilderJUnit4Tests { @Test public void testBuilderNoSteps() throws Exception { diff --git a/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestPlanBuilderJUnit5Tests.java b/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestPlanBuilderJUnit5Tests.java new file mode 100644 index 00000000..118bf436 --- /dev/null +++ b/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestPlanBuilderJUnit5Tests.java @@ -0,0 +1,50 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.statemachine.test; + +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.springframework.statemachine.test.StateMachineTestPlanBuilder.StateMachineTestPlanStep; + +public class StateMachineTestPlanBuilderJUnit5Tests { + + @Test + public void testBuilderNoSteps() throws Exception { + StateMachineTestPlan plan = + StateMachineTestPlanBuilder.builder() + .build(); + assertThat(plan, notNullValue()); + List> steps = TestUtils.readField("steps", plan); + assertThat(steps.size(), is(0)); + } + + @Test + public void testBuilderOneStep() throws Exception { + StateMachineTestPlan plan = + StateMachineTestPlanBuilder.builder() + .step().expectState("SI").and() + .build(); + assertThat(plan, notNullValue()); + List> steps = TestUtils.readField("steps", plan); + assertThat(steps.size(), is(1)); + } + +} diff --git a/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestingTests.java b/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestingJUnit4Tests.java similarity index 99% rename from spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestingTests.java rename to spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestingJUnit4Tests.java index 513c8455..481e7d30 100644 --- a/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestingTests.java +++ b/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestingJUnit4Tests.java @@ -31,7 +31,7 @@ import org.springframework.statemachine.config.StateMachineConfigurerAdapter; import org.springframework.statemachine.config.builders.StateMachineStateConfigurer; import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer; -public class StateMachineTestingTests extends AbstractStateMachineTests { +public class StateMachineTestingJUnit4Tests extends AbstractStateMachineJUnit4Tests { @Test public void testSimpleTestingConcept() throws Exception { diff --git a/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestingJUnit5Tests.java b/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestingJUnit5Tests.java new file mode 100644 index 00000000..6eb498f3 --- /dev/null +++ b/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/StateMachineTestingJUnit5Tests.java @@ -0,0 +1,315 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.statemachine.test; + +import static org.hamcrest.CoreMatchers.not; +import static org.springframework.statemachine.TestUtils.resolveMachine; + +import org.hamcrest.collection.IsMapContaining; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.task.TaskExecutor; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.statemachine.StateMachine; +import org.springframework.statemachine.config.EnableStateMachine; +import org.springframework.statemachine.config.StateMachineConfigurerAdapter; +import org.springframework.statemachine.config.builders.StateMachineStateConfigurer; +import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer; + +public class StateMachineTestingJUnit5Tests extends AbstractStateMachineJUnit5Tests { + + @Test + public void testSimpleTestingConcept() throws Exception { + registerAndRefresh(Config1.class); + StateMachine machine = resolveMachine(context); + + StateMachineTestPlan plan = + StateMachineTestPlanBuilder.builder() + .stateMachine(machine) + .step().expectState("SI").and() + .step().sendEvent("E1").expectStateChanged(1).expectState("S1").and() + .step().sendEvent("E2").expectStateChanged(1).expectState("S2").and() + .build(); + + plan.test(); + } + + @Test + public void testStarted() throws Exception { + registerAndRefresh(Config2.class); + StateMachine machine = resolveMachine(context); + + StateMachineTestPlan plan = + StateMachineTestPlanBuilder.builder() + .stateMachine(machine) + .step().expectStateMachineStarted(1).and() + .step().expectState("SI").and() + .step().sendEvent("E1").expectStateChanged(1).expectState("S1").and() + .step().sendEvent("E2").expectStateChanged(1).expectState("S2").and() + .build(); + + plan.test(); + } + + @Test + public void testMultipleEvents() throws Exception { + registerAndRefresh(Config3.class); + StateMachine machine = resolveMachine(context); + + StateMachineTestPlan plan = + StateMachineTestPlanBuilder.builder() + .stateMachine(machine) + .step().expectStateMachineStarted(1).and() + .step().expectState("READY").and() + .step() + .sendEvent("DEPLOY") + .sendEvent("DEPLOY") + .expectStateChanged(6) + .expectState("READY") + .and() + .build(); + + plan.test(); + } + + @Test + public void testIntermediate() throws Exception { + registerAndRefresh(Config4.class); + StateMachine machine = resolveMachine(context); + + StateMachineTestPlan plan = + StateMachineTestPlanBuilder.builder() + .stateMachine(machine) + .step().expectStateMachineStarted(1).and() + .step().expectState("SI").and() + .step().sendEvent("E1").expectStateChanged(1).expectState("S1").and() + .step().sendEvent("E2").expectStateChanged(2).expectStateEntered("S2", "S3").expectStateExited("S1", "S2").expectState("S3").and() + .build(); + + plan.test(); + } + + @Test + public void testVariables() throws Exception { + registerAndRefresh(Config5.class); + StateMachine machine = resolveMachine(context); + + StateMachineTestPlan plan = + StateMachineTestPlanBuilder.builder() + .stateMachine(machine) + .step().expectStateMachineStarted(1).and() + .step().expectState("SI").and() + .step() + .sendEvent("E1") + .expectStateChanged(1) + .expectState("S1") + .expectVariable("V1Key") + .expectVariable("V1Key", "V1Value") + .expectVariableWith(IsMapContaining.hasKey("V1Key")) + .expectVariableWith(IsMapContaining.hasValue("V1Value")) + .expectVariableWith(IsMapContaining.hasEntry("V1Key", "V1Value")) + .expectVariableWith(not(IsMapContaining.hasKey("V2Key"))) + .and() + .step() + .sendEvent("E2") + .expectStateChanged(1) + .expectState("S2") + .expectVariable("V1Key") + .expectVariable("V1Key", "V1Value") + .expectVariable("V2Key") + .expectVariable("V2Key", "V2Value") + .expectVariableWith(IsMapContaining.hasKey("V1Key")) + .expectVariableWith(IsMapContaining.hasValue("V1Value")) + .expectVariableWith(IsMapContaining.hasEntry("V1Key", "V1Value")) + .expectVariableWith(IsMapContaining.hasKey("V2Key")) + .expectVariableWith(IsMapContaining.hasValue("V2Value")) + .expectVariableWith(IsMapContaining.hasEntry("V2Key", "V2Value")) + .and() + .build(); + + plan.test(); + } + + @Override + protected AnnotationConfigApplicationContext buildContext() { + return new AnnotationConfigApplicationContext(); + } + + @Configuration + @EnableStateMachine + static class Config1 extends StateMachineConfigurerAdapter { + + @Override + public void configure(StateMachineStateConfigurer states) throws Exception { + states + .withStates() + .initial("SI") + .state("S1") + .state("S2"); + } + + @Override + public void configure(StateMachineTransitionConfigurer transitions) throws Exception { + transitions + .withExternal() + .source("SI") + .target("S1") + .event("E1") + .and() + .withExternal() + .source("S1") + .target("S2") + .event("E2"); + } + + } + + @Configuration + @EnableStateMachine + static class Config2 extends StateMachineConfigurerAdapter { + + @Override + public void configure(StateMachineStateConfigurer states) throws Exception { + states + .withStates() + .initial("SI") + .state("S1") + .state("S2"); + } + + @Override + public void configure(StateMachineTransitionConfigurer transitions) throws Exception { + transitions + .withExternal() + .source("SI") + .target("S1") + .event("E1") + .and() + .withExternal() + .source("S1") + .target("S2") + .event("E2"); + } + + @Bean + public TaskExecutor taskExecutor() { + ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); + taskExecutor.setCorePoolSize(1); + return taskExecutor; + } + + } + + @Configuration + @EnableStateMachine + static class Config3 extends StateMachineConfigurerAdapter { + + @Override + public void configure(StateMachineStateConfigurer states) + throws Exception { + states + .withStates() + .initial("READY") + .state("DEPLOYPREPARE", "DEPLOY") + .state("DEPLOYEXECUTE", "DEPLOY"); + } + + @Override + public void configure(StateMachineTransitionConfigurer transitions) + throws Exception { + transitions + .withExternal() + .source("READY").target("DEPLOYPREPARE") + .event("DEPLOY") + .and() + .withExternal() + .source("DEPLOYPREPARE").target("DEPLOYEXECUTE") + .and() + .withExternal() + .source("DEPLOYEXECUTE").target("READY"); + } + } + + @Configuration + @EnableStateMachine + static class Config4 extends StateMachineConfigurerAdapter { + + @Override + public void configure(StateMachineStateConfigurer states) throws Exception { + states + .withStates() + .initial("SI") + .state("S1") + .state("S2") + .state("S3"); + } + + @Override + public void configure(StateMachineTransitionConfigurer transitions) throws Exception { + transitions + .withExternal() + .source("SI") + .target("S1") + .event("E1") + .and() + .withExternal() + .source("S1") + .target("S2") + .event("E2") + .and() + .withExternal() + .source("S2") + .target("S3"); + } + + } + + @Configuration + @EnableStateMachine + static class Config5 extends StateMachineConfigurerAdapter { + + @Override + public void configure(StateMachineStateConfigurer states) throws Exception { + states + .withStates() + .initial("SI") + .state("S1") + .state("S2"); + } + + @Override + public void configure(StateMachineTransitionConfigurer transitions) throws Exception { + transitions + .withExternal() + .source("SI") + .target("S1") + .event("E1") + .action(c -> { + c.getExtendedState().getVariables().put("V1Key", "V1Value"); + }) + .and() + .withExternal() + .source("S1") + .target("S2") + .event("E2") + .action(c -> { + c.getExtendedState().getVariables().put("V2Key", "V2Value"); + }); + } + } +} diff --git a/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/docs/DocsTestSampleTests.java b/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/docs/DocsTestSampleTests.java index 9ff6cd91..75955249 100644 --- a/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/docs/DocsTestSampleTests.java +++ b/spring-statemachine-test/src/test/java/org/springframework/statemachine/test/docs/DocsTestSampleTests.java @@ -19,10 +19,12 @@ package org.springframework.statemachine.test.docs; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.collection.IsMapContaining.hasKey; import static org.hamcrest.collection.IsMapContaining.hasValue; + +import org.junit.jupiter.api.Test; + import static org.hamcrest.collection.IsMapContaining.hasEntry; //end::snippetC[] -import org.junit.Test; import org.springframework.statemachine.StateMachine; import org.springframework.statemachine.config.StateMachineBuilder; import org.springframework.statemachine.test.StateMachineTestPlan;