From fab5ea4fbba4eb1841e552bbe8dcd9b5b061cc63 Mon Sep 17 00:00:00 2001 From: Michael Siepmann Date: Sat, 19 Dec 2020 22:49:33 +0100 Subject: [PATCH] Update to JUnit 5. --- pom.xml | 13 ++++++++++--- .../java/me/tongfei/progressbar/Issue13Test.java | 9 +++++---- .../java/me/tongfei/progressbar/Issue40Test.java | 6 +++--- .../java/me/tongfei/progressbar/Issue50Test.java | 10 ++++++---- .../java/me/tongfei/progressbar/Issue84Test.java | 10 ++++++---- .../tongfei/progressbar/MultiProgressBarTest.java | 6 +++--- .../me/tongfei/progressbar/PauseResumeTest.java | 6 +++--- .../me/tongfei/progressbar/ProgressBarTest.java | 14 ++++++++------ .../java/me/tongfei/progressbar/RangeTest.java | 8 ++++---- .../java/me/tongfei/progressbar/Slf4jTest.java | 6 +++--- .../me/tongfei/progressbar/SpeedDisplayTest.java | 8 ++++---- .../tongfei/progressbar/WrappedIterableTest.java | 6 +++--- 12 files changed, 58 insertions(+), 44 deletions(-) diff --git a/pom.xml b/pom.xml index c449dc4..9a7398a 100644 --- a/pom.xml +++ b/pom.xml @@ -108,9 +108,16 @@ - junit - junit - 4.13 + org.junit.jupiter + junit-jupiter-api + 5.7.0 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.7.0 test diff --git a/src/test/java/me/tongfei/progressbar/Issue13Test.java b/src/test/java/me/tongfei/progressbar/Issue13Test.java index 62a1bbb..c3d2c1c 100644 --- a/src/test/java/me/tongfei/progressbar/Issue13Test.java +++ b/src/test/java/me/tongfei/progressbar/Issue13Test.java @@ -1,17 +1,18 @@ package me.tongfei.progressbar; -import org.junit.Test; + +import org.junit.jupiter.api.Test; /** * @author bwittwer */ -public class Issue13Test { +class Issue13Test { private static final int NBR_ELEMENTS = 100; private static final int PROGRESSBAR_GRACE_PERIOD = 1000; @Test - public void testOk() { + void testOk() { try (ProgressBar pb = new ProgressBar("Test", NBR_ELEMENTS)) { try { @@ -27,7 +28,7 @@ public void testOk() { } @Test - public void testKo() { + void testKo() { try (ProgressBar pb = new ProgressBar("Test", NBR_ELEMENTS)) { for (int i = 0; i < 100; i++) { diff --git a/src/test/java/me/tongfei/progressbar/Issue40Test.java b/src/test/java/me/tongfei/progressbar/Issue40Test.java index 10ad990..8e5ae20 100644 --- a/src/test/java/me/tongfei/progressbar/Issue40Test.java +++ b/src/test/java/me/tongfei/progressbar/Issue40Test.java @@ -1,6 +1,6 @@ package me.tongfei.progressbar; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -9,10 +9,10 @@ /** * @author Tongfei Chen */ -public class Issue40Test { +class Issue40Test { @Test - public void test() throws InterruptedException { + void test() throws InterruptedException { InputStream input = new ByteArrayInputStream("100 200 300".getBytes()); Scanner sc = new Scanner(input); diff --git a/src/test/java/me/tongfei/progressbar/Issue50Test.java b/src/test/java/me/tongfei/progressbar/Issue50Test.java index 9658ead..54efd6f 100644 --- a/src/test/java/me/tongfei/progressbar/Issue50Test.java +++ b/src/test/java/me/tongfei/progressbar/Issue50Test.java @@ -1,10 +1,12 @@ package me.tongfei.progressbar; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class Issue50Test { +import static org.junit.jupiter.api.Assertions.assertTrue; + +class Issue50Test { @Test - public void testCloseSpeed() throws Exception { + void testCloseSpeed() throws Exception { int tenSecondsInMS = 10 * 1000; long startTime = System.currentTimeMillis(); @@ -15,6 +17,6 @@ public void testCloseSpeed() throws Exception { long endTime = System.currentTimeMillis(); - assert((endTime - startTime) < tenSecondsInMS); + assertTrue((endTime - startTime) < tenSecondsInMS); } } diff --git a/src/test/java/me/tongfei/progressbar/Issue84Test.java b/src/test/java/me/tongfei/progressbar/Issue84Test.java index 9590c18..033211d 100644 --- a/src/test/java/me/tongfei/progressbar/Issue84Test.java +++ b/src/test/java/me/tongfei/progressbar/Issue84Test.java @@ -1,19 +1,21 @@ package me.tongfei.progressbar; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; import java.io.PrintStream; +import static org.junit.jupiter.api.Assertions.assertFalse; + /** * @author Andrei Nakrasov */ -public class Issue84Test { +class Issue84Test { private final static int iterNumber = 100; private final static int criticalExtraMsgLen = 38; @Test - public void testLongExtraMessage() { + void testLongExtraMessage() { // redirect all exception messages to a new stream // https://stackoverflow.com/a/8708357 @@ -39,6 +41,6 @@ public void testLongExtraMessage() { String exceptionMsgChecker = baos.toString(); System.setErr(old); // Exception is handled in ProgressThread run, so in test output is checked for exceptions - assert (!exceptionMsgChecker.contains("Exception")); + assertFalse(exceptionMsgChecker.contains("Exception")); } } diff --git a/src/test/java/me/tongfei/progressbar/MultiProgressBarTest.java b/src/test/java/me/tongfei/progressbar/MultiProgressBarTest.java index a4c7e3a..85e147f 100644 --- a/src/test/java/me/tongfei/progressbar/MultiProgressBarTest.java +++ b/src/test/java/me/tongfei/progressbar/MultiProgressBarTest.java @@ -1,12 +1,12 @@ package me.tongfei.progressbar; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class MultiProgressBarTest { +class MultiProgressBarTest { @Test - public void testMultiProgressBar() throws InterruptedException { + void testMultiProgressBar() throws InterruptedException { try ( ProgressBar pb1 = new ProgressBar("PB1", 100); diff --git a/src/test/java/me/tongfei/progressbar/PauseResumeTest.java b/src/test/java/me/tongfei/progressbar/PauseResumeTest.java index 2d3098a..28a8c49 100644 --- a/src/test/java/me/tongfei/progressbar/PauseResumeTest.java +++ b/src/test/java/me/tongfei/progressbar/PauseResumeTest.java @@ -1,11 +1,11 @@ package me.tongfei.progressbar; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class PauseResumeTest { +class PauseResumeTest { @Test - public void testPauseResume() { + void testPauseResume() { try (ProgressBar pb = new ProgressBarBuilder() .setTaskName("Test").setInitialMax(10).setUpdateIntervalMillis(100).build()) { try { diff --git a/src/test/java/me/tongfei/progressbar/ProgressBarTest.java b/src/test/java/me/tongfei/progressbar/ProgressBarTest.java index 445757e..5e53981 100644 --- a/src/test/java/me/tongfei/progressbar/ProgressBarTest.java +++ b/src/test/java/me/tongfei/progressbar/ProgressBarTest.java @@ -1,19 +1,20 @@ package me.tongfei.progressbar; +import org.junit.jupiter.api.Test; + import java.text.DecimalFormat; import java.time.Duration; import java.time.temporal.ChronoUnit; -import org.junit.Test; import java.util.ArrayList; /** * @author Tongfei Chen */ -public class ProgressBarTest { +class ProgressBarTest { @Test - public void test() { + void test() { try (ProgressBar pb = new ProgressBarBuilder() .setTaskName("Test").setInitialMax(5).setUpdateIntervalMillis(50) .setStyle(ProgressBarStyle.UNICODE_BLOCK).setUnit("K", 1024).build()) { @@ -39,7 +40,7 @@ public void test() { System.out.println("Hello"); } @Test - public void testSpeedFormat() throws InterruptedException { + void testSpeedFormat() throws InterruptedException { ProgressBar bar = new ProgressBarBuilder() .showSpeed(new DecimalFormat("#.##")) .setUnit("k", 1000) @@ -55,7 +56,7 @@ public void testSpeedFormat() throws InterruptedException { bar.close(); } @Test - public void testSpeedUnit() throws InterruptedException { + void testSpeedUnit() throws InterruptedException { ProgressBar bar = new ProgressBarBuilder() .showSpeed(new DecimalFormat("#.####")) .setUnit("k", 1000) @@ -71,8 +72,9 @@ public void testSpeedUnit() throws InterruptedException { bar.close(); } + @Test - public void testSpeedStartFrom() throws InterruptedException { + void testSpeedStartFrom() throws InterruptedException { ProgressBar bar = new ProgressBarBuilder() .showSpeed(new DecimalFormat("#.##")) .setUnit("k", 1000) diff --git a/src/test/java/me/tongfei/progressbar/RangeTest.java b/src/test/java/me/tongfei/progressbar/RangeTest.java index 58c9e56..1cba257 100644 --- a/src/test/java/me/tongfei/progressbar/RangeTest.java +++ b/src/test/java/me/tongfei/progressbar/RangeTest.java @@ -1,16 +1,16 @@ package me.tongfei.progressbar; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.stream.IntStream; /** * @author Tongfei Chen */ -public class RangeTest { +class RangeTest { @Test - public void parallelRangeTest() { + void parallelRangeTest() { ProgressBar.wrap(IntStream.range(1000, 9000).parallel(), "Test parallel").forEach(i -> { try { Thread.sleep(10); @@ -20,7 +20,7 @@ public void parallelRangeTest() { } @Test - public void sequentialRangeTest() { + void sequentialRangeTest() { ProgressBar.wrap(IntStream.range(1000, 2000), "Test sequential").forEach(i -> { try { Thread.sleep(10); diff --git a/src/test/java/me/tongfei/progressbar/Slf4jTest.java b/src/test/java/me/tongfei/progressbar/Slf4jTest.java index 32b8b88..d194741 100644 --- a/src/test/java/me/tongfei/progressbar/Slf4jTest.java +++ b/src/test/java/me/tongfei/progressbar/Slf4jTest.java @@ -1,17 +1,17 @@ package me.tongfei.progressbar; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author Alex Peelman */ -public class Slf4jTest { +class Slf4jTest { //Prints progress as new lines without carriage return @Test - public void printLoggerTest() throws InterruptedException { + void printLoggerTest() throws InterruptedException { final Logger logger = LoggerFactory.getLogger("Test"); try (ProgressBar pb = new ProgressBarBuilder() .setInitialMax(100) diff --git a/src/test/java/me/tongfei/progressbar/SpeedDisplayTest.java b/src/test/java/me/tongfei/progressbar/SpeedDisplayTest.java index 8fe517a..8d20aa6 100644 --- a/src/test/java/me/tongfei/progressbar/SpeedDisplayTest.java +++ b/src/test/java/me/tongfei/progressbar/SpeedDisplayTest.java @@ -1,13 +1,13 @@ package me.tongfei.progressbar; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.text.DecimalFormat; -public class SpeedDisplayTest { +class SpeedDisplayTest { @Test - public void test() throws InterruptedException { + void test() throws InterruptedException { ProgressBar bar = new ProgressBarBuilder() .showSpeed() .setUnit("k", 1000) @@ -24,7 +24,7 @@ public void test() throws InterruptedException { } @Test - public void testSpeedFormat() throws InterruptedException { + void testSpeedFormat() throws InterruptedException { ProgressBar bar = new ProgressBarBuilder() .showSpeed(new DecimalFormat("#.##")) .setUnit("k", 1000) diff --git a/src/test/java/me/tongfei/progressbar/WrappedIterableTest.java b/src/test/java/me/tongfei/progressbar/WrappedIterableTest.java index 55888cf..c92ef33 100644 --- a/src/test/java/me/tongfei/progressbar/WrappedIterableTest.java +++ b/src/test/java/me/tongfei/progressbar/WrappedIterableTest.java @@ -1,6 +1,6 @@ package me.tongfei.progressbar; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.stream.Collectors; @@ -9,10 +9,10 @@ /** * @author Tongfei Chen */ -public class WrappedIterableTest { +class WrappedIterableTest { @Test - public void test() throws Exception { + void test() throws Exception { List sizedColl = Stream.iterate(1, x -> x + 1).limit(10000).collect(Collectors.toList());