Port samples tests to assertj
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
* Copyright 2015-2020 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.
|
||||
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
package demo.tasks;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.statemachine.TestUtils.doStartAndAssert;
|
||||
import static org.springframework.statemachine.TestUtils.doStopAndAssert;
|
||||
|
||||
@@ -64,36 +62,36 @@ public class TasksTests {
|
||||
@Test
|
||||
public void testInitialState() throws InterruptedException {
|
||||
Map<Object, Object> variables = machine.getExtendedState().getVariables();
|
||||
assertThat(variables.size(), is(0));
|
||||
assertThat(variables).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRunOnce() throws InterruptedException {
|
||||
listener.reset(8, 8, 0);
|
||||
tasks.run();
|
||||
assertThat(listener.stateEnteredLatch.await(8, TimeUnit.SECONDS), is(true));
|
||||
assertThat(machine.getState().getIds(), contains(States.READY));
|
||||
assertThat(listener.stateEnteredLatch.await(8, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(machine.getState().getIds()).containsExactly(States.READY);
|
||||
Map<Object, Object> variables = machine.getExtendedState().getVariables();
|
||||
assertThat(variables.size(), is(3));
|
||||
assertThat(variables).hasSize(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRunTwice() throws InterruptedException {
|
||||
listener.reset(8, 8, 0);
|
||||
tasks.run();
|
||||
assertThat(listener.stateEnteredLatch.await(8, TimeUnit.SECONDS), is(true));
|
||||
assertThat(machine.getState().getIds(), contains(States.READY));
|
||||
assertThat(listener.stateEnteredLatch.await(8, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(machine.getState().getIds()).containsExactly(States.READY);
|
||||
|
||||
Map<Object, Object> variables = machine.getExtendedState().getVariables();
|
||||
assertThat(variables.size(), is(3));
|
||||
assertThat(variables).hasSize(3);
|
||||
|
||||
listener.reset(8, 8, 0);
|
||||
tasks.run();
|
||||
assertThat(listener.stateEnteredLatch.await(8, TimeUnit.SECONDS), is(true));
|
||||
assertThat(machine.getState().getIds(), contains(States.READY));
|
||||
assertThat(listener.stateEnteredLatch.await(8, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(machine.getState().getIds()).containsExactly(States.READY);
|
||||
|
||||
variables = machine.getExtendedState().getVariables();
|
||||
assertThat(variables.size(), is(3));
|
||||
assertThat(variables).hasSize(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,8 +104,8 @@ public class TasksTests {
|
||||
|
||||
boolean await = listener.stateEnteredLatch.await(8, TimeUnit.SECONDS);
|
||||
String reason = "Machine was " + machine + " " + StringUtils.collectionToCommaDelimitedString(listener.statesEntered);
|
||||
assertThat(reason , await, is(true));
|
||||
assertThat(machine.getState().getIds(), contains(States.READY));
|
||||
assertThat(await).isTrue().withFailMessage(reason);
|
||||
assertThat(machine.getState().getIds()).containsExactly(States.READY);
|
||||
log.info("testRunSmoke SMOKE STOP " + i);
|
||||
}
|
||||
}
|
||||
@@ -117,9 +115,9 @@ public class TasksTests {
|
||||
listener.reset(10, 0, 0);
|
||||
tasks.fail("T1");
|
||||
tasks.run();
|
||||
assertThat(listener.stateChangedLatch.await(6, TimeUnit.SECONDS), is(true));
|
||||
assertThat(listener.stateChangedCount, is(10));
|
||||
assertThat(machine.getState().getIds(), contains(States.READY));
|
||||
assertThat(listener.stateChangedLatch.await(6, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(listener.stateChangedCount).isEqualTo(10);
|
||||
assertThat(machine.getState().getIds()).containsExactly(States.READY);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,16 +125,16 @@ public class TasksTests {
|
||||
listener.reset(10, 0, 0);
|
||||
tasks.fail("T2");
|
||||
tasks.run();
|
||||
assertThat(listener.stateChangedLatch.await(6, TimeUnit.SECONDS), is(true));
|
||||
assertThat(listener.stateChangedLatch.await(6, TimeUnit.SECONDS)).isTrue();
|
||||
|
||||
Map<Object, Object> variables = machine.getExtendedState().getVariables();
|
||||
assertThat(variables.size(), is(3));
|
||||
assertThat(variables).hasSize(3);
|
||||
|
||||
assertThat(machine.getState().getIds(), contains(States.ERROR, States.MANUAL));
|
||||
assertThat(machine.getState().getIds()).containsExactly(States.ERROR, States.MANUAL);
|
||||
listener.reset(1, 0, 0);
|
||||
tasks.fix();
|
||||
assertThat(listener.stateChangedLatch.await(6, TimeUnit.SECONDS), is(true));
|
||||
assertThat(machine.getState().getIds(), contains(States.READY));
|
||||
assertThat(listener.stateChangedLatch.await(6, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(machine.getState().getIds()).containsExactly(States.READY);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -149,9 +147,9 @@ public class TasksTests {
|
||||
tasks = context.getBean(Tasks.class);
|
||||
listener = context.getBean(TestListener.class);
|
||||
doStartAndAssert(machine);
|
||||
assertThat(listener.stateChangedLatch.await(1, TimeUnit.SECONDS), is(true));
|
||||
assertThat(listener.stateChangedCount, is(1));
|
||||
assertThat(machine.getState().getIds(), contains(States.READY));
|
||||
assertThat(listener.stateChangedLatch.await(1, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(listener.stateChangedCount).isEqualTo(1);
|
||||
assertThat(machine.getState().getIds()).containsExactly(States.READY);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
||||
Reference in New Issue
Block a user