From 07cf9245784f1643de3fc1985890d761a48e3243 Mon Sep 17 00:00:00 2001 From: Janne Valkealahti Date: Sat, 28 Nov 2020 19:56:11 +0000 Subject: [PATCH] Port build-tests tests to assertj --- build.gradle | 2 - .../buildtests/EndSmokeTests.java | 10 ++-- .../statemachine/buildtests/Gh737Tests.java | 11 ++--- .../buildtests/LinkedRegionsTests.java | 13 +++--- .../buildtests/RedisPersistTests.java | 46 +++++++++---------- 5 files changed, 37 insertions(+), 45 deletions(-) diff --git a/build.gradle b/build.gradle index 11192c1e..7602b52b 100644 --- a/build.gradle +++ b/build.gradle @@ -437,8 +437,6 @@ project('spring-statemachine-build-tests') { testCompile 'com.h2database:h2' testCompile 'org.springframework.boot:spring-boot-starter' testCompile 'org.springframework:spring-test' - testCompile 'org.hamcrest:hamcrest-core' - testCompile 'org.hamcrest:hamcrest-library' } } 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 cc649ccd..78d2a6dc 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 @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-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 org.springframework.statemachine.buildtests; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.MatcherAssert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -55,8 +53,8 @@ public class EndSmokeTests extends AbstractBuildTests { t.runWhile = false; t.join(); - assertThat(t.e, nullValue()); - assertThat(t.ok, is(true)); + assertThat(t.e).isNull(); + assertThat(t.ok).isTrue(); } private static class TestThread extends Thread { 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 d48c87f3..05194702 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 @@ -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,11 +15,10 @@ */ package org.springframework.statemachine.buildtests; -import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.assertj.core.api.Assertions.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; @@ -40,11 +39,11 @@ public class Gh737Tests extends AbstractBuildTests { StateMachine machine = resolveMachine(context); doStartAndAssert(machine); - assertThat(machine.getState().getIds(), containsInAnyOrder(Status.ROOT, Status.S0)); + assertThat(machine.getState().getIds()).containsOnly(Status.ROOT, Status.S0); doSendEventAndConsumeAll(machine, Event.NEW); - assertThat(machine.getState().getIds(), containsInAnyOrder(Status.ROOT, Status.S2, Status.S21I, Status.S22I, - Status.S23_IN_PROGRESS, Status.S24E)); + assertThat(machine.getState().getIds()).containsOnly(Status.ROOT, Status.S2, Status.S21I, Status.S22I, + Status.S23_IN_PROGRESS, Status.S24E); } @Configuration 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 d536ec9a..5e0bc8fc 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 @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-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,10 +15,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.hamcrest.MatcherAssert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import java.util.ArrayList; @@ -54,7 +51,11 @@ public class LinkedRegionsTests extends AbstractBuildTests { .step().expectStateChanged(15).expectStates("S3").and() .build(); plan.test(); - assertThat(listener.statesEntered, not(hasItem(startsWith("JOIN")))); + assertThat(listener.statesEntered).satisfies(l -> { + l.forEach(s -> { + assertThat(s).doesNotStartWith("JOIN"); + }); + }); } @Configuration 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 ea9298e5..fca2b38c 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 @@ -1,5 +1,5 @@ /* - * Copyright 2017-2019 the original author or authors. + * Copyright 2017-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,11 +15,7 @@ */ package org.springframework.statemachine.buildtests; -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.hamcrest.MatcherAssert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.statemachine.TestUtils.doSendEventAndConsumeAll; import static org.springframework.statemachine.TestUtils.doStartAndAssert; import static org.springframework.statemachine.TestUtils.resolveFactory; @@ -62,45 +58,45 @@ public class RedisPersistTests extends AbstractBuildTests { StateMachine stateMachine = stateMachineFactory.getStateMachine("testid"); doStartAndAssert(stateMachine); - assertThat(stateMachine, notNullValue()); - assertThat(stateMachine.getId(), is("testid")); + assertThat(stateMachine).isNotNull(); + assertThat(stateMachine.getId()).isEqualTo("testid"); doSendEventAndConsumeAll(stateMachine, TestEvents.E1); - assertThat(stateMachine.getState().getIds(), containsInAnyOrder(TestStates.S2, TestStates.S20, TestStates.S30)); + assertThat(stateMachine.getState().getIds()).containsOnly(TestStates.S2, TestStates.S20, TestStates.S30); persister.persist(stateMachine, "xxx1"); doSendEventAndConsumeAll(stateMachine, TestEvents.E2); - assertThat(stateMachine.getState().getIds(), containsInAnyOrder(TestStates.S2, TestStates.S21, TestStates.S30)); + assertThat(stateMachine.getState().getIds()).containsOnly(TestStates.S2, TestStates.S21, TestStates.S30); persister.persist(stateMachine, "xxx2"); doSendEventAndConsumeAll(stateMachine, TestEvents.E3); - assertThat(stateMachine.getState().getIds(), containsInAnyOrder(TestStates.S4)); + assertThat(stateMachine.getState().getIds()).containsOnly(TestStates.S4); persister.persist(stateMachine, "xxx3"); stateMachine = stateMachineFactory.getStateMachine(); - assertThat(stateMachine, notNullValue()); - assertThat(stateMachine.getId(), nullValue()); + assertThat(stateMachine).isNotNull(); + assertThat(stateMachine.getId()).isNull(); stateMachine = persister.restore(stateMachine, "xxx1"); - assertThat(stateMachine.getId(), is("testid")); - assertThat(stateMachine.getState().getIds(), containsInAnyOrder(TestStates.S2, TestStates.S20, TestStates.S30)); + assertThat(stateMachine.getId()).isEqualTo("testid"); + assertThat(stateMachine.getState().getIds()).containsOnly(TestStates.S2, TestStates.S20, TestStates.S30); doSendEventAndConsumeAll(stateMachine, TestEvents.E2); - assertThat(stateMachine.getState().getIds(), containsInAnyOrder(TestStates.S2, TestStates.S21, TestStates.S30)); + assertThat(stateMachine.getState().getIds()).containsOnly(TestStates.S2, TestStates.S21, TestStates.S30); stateMachine = stateMachineFactory.getStateMachine(); - assertThat(stateMachine, notNullValue()); - assertThat(stateMachine.getId(), nullValue()); + assertThat(stateMachine).isNotNull(); + assertThat(stateMachine.getId()).isNull(); stateMachine = persister.restore(stateMachine, "xxx2"); - assertThat(stateMachine.getId(), is("testid")); - assertThat(stateMachine.getState().getIds(), containsInAnyOrder(TestStates.S2, TestStates.S21, TestStates.S30)); + assertThat(stateMachine.getId()).isEqualTo("testid"); + assertThat(stateMachine.getState().getIds()).containsOnly(TestStates.S2, TestStates.S21, TestStates.S30); doSendEventAndConsumeAll(stateMachine, TestEvents.E3); - assertThat(stateMachine.getState().getIds(), containsInAnyOrder(TestStates.S4)); + assertThat(stateMachine.getState().getIds()).containsOnly(TestStates.S4); stateMachine = stateMachineFactory.getStateMachine(); - assertThat(stateMachine, notNullValue()); - assertThat(stateMachine.getId(), nullValue()); + assertThat(stateMachine).isNotNull(); + assertThat(stateMachine.getId()).isNull(); stateMachine = persister.restore(stateMachine, "xxx3"); - assertThat(stateMachine.getId(), is("testid")); - assertThat(stateMachine.getState().getIds(), containsInAnyOrder(TestStates.S4)); + assertThat(stateMachine.getId()).isEqualTo("testid"); + assertThat(stateMachine.getState().getIds()).containsOnly(TestStates.S4); } @Configuration