From 4bb7c595c2d63e8d05c2f3848bbe871998d87b5b Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Sun, 20 Oct 2019 11:51:34 +0200 Subject: [PATCH] update Hamcrest library for testing --- pom.xml | 8 ++--- .../stklcode/pubtrans/ura/UraClientTest.java | 2 +- .../ura/reader/AsyncUraTripReaderTest.java | 29 ++++++++++--------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index df42f7b..cfc7433 100644 --- a/pom.xml +++ b/pom.xml @@ -65,20 +65,20 @@ org.hamcrest - hamcrest-junit - 2.0.0.0 + hamcrest + 2.2 test net.bytebuddy byte-buddy - 1.10.1 + 1.10.2 test net.bytebuddy byte-buddy-agent - 1.10.1 + 1.10.2 test diff --git a/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java b/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java index 2f4276b..f997bff 100644 --- a/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java +++ b/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java @@ -21,8 +21,8 @@ import de.stklcode.pubtrans.ura.model.Trip; import net.bytebuddy.ByteBuddy; import net.bytebuddy.agent.ByteBuddyAgent; import net.bytebuddy.dynamic.loading.ClassReloadingStrategy; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.InputStream; diff --git a/src/test/java/de/stklcode/pubtrans/ura/reader/AsyncUraTripReaderTest.java b/src/test/java/de/stklcode/pubtrans/ura/reader/AsyncUraTripReaderTest.java index 0b0c397..5192baa 100644 --- a/src/test/java/de/stklcode/pubtrans/ura/reader/AsyncUraTripReaderTest.java +++ b/src/test/java/de/stklcode/pubtrans/ura/reader/AsyncUraTripReaderTest.java @@ -27,7 +27,10 @@ import org.junit.jupiter.api.Test; import java.io.*; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayDeque; +import java.util.Collections; +import java.util.Deque; +import java.util.Queue; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -35,10 +38,8 @@ import java.util.concurrent.atomic.AtomicInteger; import static net.bytebuddy.implementation.MethodDelegation.to; import static net.bytebuddy.matcher.ElementMatchers.named; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.empty; import static org.hamcrest.core.Is.is; -import static org.junit.Assume.assumeThat; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** * Unit test for the asynchronous URA Trip reader. @@ -95,11 +96,11 @@ public class AsyncUraTripReaderTest { tr.open(); // Read for 1 second. TimeUnit.SECONDS.sleep(1); - assumeThat("Trips should empty after 1s without reading", trips, is(empty())); + assumeTrue(trips.isEmpty(), "Trips should empty after 1s without reading"); // Now write a single line to the stream pipe. - assumeTrue("First line (version info) should be written", writeNextLine()); - assumeTrue("Second line (first record) should be written", writeNextLine()); + assumeTrue(writeNextLine(), "First line (version info) should be written"); + assumeTrue(writeNextLine(), "Second line (first record) should be written"); // Wait up to 1s for the callback to be triggered. int i = 10; @@ -136,10 +137,10 @@ public class AsyncUraTripReaderTest { tr.open(); // Read for 1 second. TimeUnit.SECONDS.sleep(1); - assumeThat("Trips should empty after 1s without reading", trips, is(empty())); + assumeTrue(trips.isEmpty(), "Trips should empty after 1s without reading"); - assumeTrue("First line of v2 (version info) should be written", writeNextLine()); - assumeTrue("Second line of v2 (first record) should be written", writeNextLine()); + assumeTrue(writeNextLine(), "First line of v2 (version info) should be written"); + assumeTrue(writeNextLine(), "Second line of v2 (first record) should be written"); i = 10; counter.set(0); @@ -202,11 +203,11 @@ public class AsyncUraTripReaderTest { // Read for 100ms. TimeUnit.MILLISECONDS.sleep(100); - assumeThat("Trips should empty after 100ms without reading", trips, is(empty())); + assumeTrue(trips.isEmpty(), "Trips should empty after 100ms without reading"); // Now write a single line to the stream pipe. - assumeTrue("First line (version info) should be written", writeNextLine()); - assumeTrue("Second line (first record) should be written", writeNextLine()); + assumeTrue(writeNextLine(), "First line (version info) should be written"); + assumeTrue(writeNextLine(), "Second line (first record) should be written"); // Wait up to 1s for the callback to be triggered. int i = 10; @@ -214,7 +215,7 @@ public class AsyncUraTripReaderTest { TimeUnit.MILLISECONDS.sleep(100); } - assumeThat("Unexpected number of trips after first entry", trips.size(), is(1)); + assumeTrue(1 == trips.size(), "Unexpected number of trips after first entry"); // Close the stream. mockOutputStream.close();