Skip to content

Commit

Permalink
Update to JUnit 5.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsiepmann authored and ctongfei committed Feb 26, 2021
1 parent e8fd860 commit fab5ea4
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 44 deletions.
13 changes: 10 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,16 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>

Expand Down
9 changes: 5 additions & 4 deletions src/test/java/me/tongfei/progressbar/Issue13Test.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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++) {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/me/tongfei/progressbar/Issue40Test.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions src/test/java/me/tongfei/progressbar/Issue50Test.java
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -15,6 +17,6 @@ public void testCloseSpeed() throws Exception {

long endTime = System.currentTimeMillis();

assert((endTime - startTime) < tenSecondsInMS);
assertTrue((endTime - startTime) < tenSecondsInMS);
}
}
10 changes: 6 additions & 4 deletions src/test/java/me/tongfei/progressbar/Issue84Test.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/me/tongfei/progressbar/PauseResumeTest.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
14 changes: 8 additions & 6 deletions src/test/java/me/tongfei/progressbar/ProgressBarTest.java
Original file line number Diff line number Diff line change
@@ -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()) {
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/me/tongfei/progressbar/RangeTest.java
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/me/tongfei/progressbar/Slf4jTest.java
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/me/tongfei/progressbar/SpeedDisplayTest.java
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/me/tongfei/progressbar/WrappedIterableTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,10 +9,10 @@
/**
* @author Tongfei Chen
*/
public class WrappedIterableTest {
class WrappedIterableTest {

@Test
public void test() throws Exception {
void test() throws Exception {

List<Integer> sizedColl = Stream.iterate(1, x -> x + 1).limit(10000).collect(Collectors.toList());

Expand Down

0 comments on commit fab5ea4

Please sign in to comment.