Skip to content

Commit 9117b6c

Browse files
authored
[SDK-4366] Update to JUnit 5 (#546)
1 parent cf1e5e5 commit 9117b6c

148 files changed

Lines changed: 1483 additions & 1551 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ test {
6060
events "skipped", "failed"
6161
exceptionFormat "short"
6262
}
63+
useJUnitPlatform()
6364
}
6465

6566
ext {
6667
okhttpVersion = '4.10.0'
6768
hamcrestVersion = '2.2'
69+
jupiterVersion = '5.9.3'
6870
}
6971

7072
dependencies {
@@ -77,9 +79,9 @@ dependencies {
7779
testImplementation "org.bouncycastle:bcprov-jdk15on:1.68"
7880
testImplementation "org.mockito:mockito-core:4.8.1"
7981
testImplementation "com.squareup.okhttp3:mockwebserver:${okhttpVersion}"
80-
testImplementation "org.hamcrest:hamcrest-core:${hamcrestVersion}"
81-
testImplementation "org.hamcrest:hamcrest-library:${hamcrestVersion}"
82-
testImplementation "junit:junit:4.13.1"
82+
testImplementation "org.hamcrest:hamcrest:${hamcrestVersion}"
83+
testImplementation "org.junit.jupiter:junit-jupiter-api:${jupiterVersion}"
84+
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${jupiterVersion}"
8385
}
8486

8587
// Creates a version.txt file containing the current version of the SDK.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.auth0;
2+
3+
import org.junit.jupiter.api.function.Executable;
4+
5+
import static org.hamcrest.MatcherAssert.assertThat;
6+
import static org.hamcrest.Matchers.is;
7+
import static org.junit.jupiter.api.Assertions.assertThrows;
8+
9+
public class AssertsUtil {
10+
11+
public static <T extends Throwable> T verifyThrows(Class<T> expectedType, Executable executable) {
12+
return assertThrows(expectedType, executable);
13+
}
14+
15+
public static <T extends Throwable> T verifyThrows(Class<T> expectedType, Executable executable, String message) {
16+
T result = assertThrows(expectedType, executable);
17+
assertThat(result.getMessage(), is(message));
18+
return result;
19+
}
20+
}

src/test/java/com/auth0/client/HttpOptionsTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.auth0.client;
22

3-
import org.junit.Test;
4-
import static org.junit.Assert.assertThrows;
3+
import org.junit.jupiter.api.Test;
54

5+
import static com.auth0.AssertsUtil.verifyThrows;
66
import static org.hamcrest.MatcherAssert.assertThat;
7-
import static org.hamcrest.Matchers.*;
7+
import static org.hamcrest.Matchers.is;
88

99
@SuppressWarnings("deprecation")
1010
public class HttpOptionsTest {
@@ -44,29 +44,28 @@ public void readTimeoutMustNotBeNegative() {
4444
@Test
4545
public void apiMaxRetriesNotLessThan0() {
4646
HttpOptions opts = new HttpOptions();
47-
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> opts.setManagementAPIMaxRetries(-1));
48-
assertThat(exception.getMessage(), is("Retries must be between zero and ten."));
47+
verifyThrows(IllegalArgumentException.class,
48+
() -> opts.setManagementAPIMaxRetries(-1),
49+
"Retries must be between zero and ten.");
4950
}
5051

5152
@Test
5253
public void apiMaxRetriesNotGreaterThan10() {
5354
HttpOptions opts = new HttpOptions();
54-
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> opts.setManagementAPIMaxRetries(11));
55-
assertThat(exception.getMessage(), is("Retries must be between zero and ten."));
55+
verifyThrows(IllegalArgumentException.class,
56+
() -> opts.setManagementAPIMaxRetries(11),
57+
"Retries must be between zero and ten.");
5658
}
5759

5860
@Test
5961
public void maxRequestsMustBePositive() {
6062
HttpOptions opts = new HttpOptions();
61-
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> opts.setMaxRequests(0));
62-
assertThat(exception.getMessage(), is("maxRequests must be one or greater."));
63+
verifyThrows(IllegalArgumentException.class, () -> opts.setMaxRequests(0), "maxRequests must be one or greater.");
6364
}
6465

6566
@Test
6667
public void maxRequestsPerHostMustBePositive() {
6768
HttpOptions opts = new HttpOptions();
68-
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> opts.setMaxRequestsPerHost(0));
69-
assertThat(exception.getMessage(), is("maxRequestsPerHost must be one or greater."));
7069
}
7170

7271
@Test

0 commit comments

Comments
 (0)