Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate servicetalk-buffer-api tests to JUnit 5 (#1568) #1592

Merged
merged 1 commit into from
Jun 1, 2021

Conversation

kashike
Copy link
Contributor

@kashike kashike commented May 29, 2021

Motivation:

  • JUnit 5 leverages features from Java 8 or later, such as lambda functions, making tests more powerful and easier to maintain.
  • JUnit 5 has added some very useful new features for describing, organizing, and executing tests. For instance, tests get better display names and can be organized hierarchically.
  • JUnit 5 is organized into multiple libraries, so only the features you need are imported into your project. With build systems such as Maven and Gradle, including the right libraries is easy.
  • JUnit 5 can use more than one extension at a time, which JUnit 4 could not (only one runner could be used at a time). This means you can easily combine the Spring extension with other extensions (such as your own custom extension).

Modifications:

  • Unit tests have been migrated from JUnit 4 to JUnit 5

Result:

Module servicetalk-buffer-api now runs tests using JUnit 5

@kashike kashike mentioned this pull request May 29, 2021
44 tasks
@kashike kashike force-pushed the feature/junit-5/buffer-api branch from 9240f42 to c0f24d9 Compare May 29, 2021 01:16
Copy link
Contributor

@tkountis tkountis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make all test methods pkg private.

Since you are in there do you mind also making this small change,
the null check is not needed since the parent class does check for null.

diff --git a/servicetalk-buffer-api/src/testFixtures/java/io/servicetalk/buffer/api/Matchers.java b/servicetalk-buffer-api/src/testFixtures/java/io/servicetalk/buffer/api/Matchers.java
index 2db5f8c31..c95ac0819 100644
--- a/servicetalk-buffer-api/src/testFixtures/java/io/servicetalk/buffer/api/Matchers.java
+++ b/servicetalk-buffer-api/src/testFixtures/java/io/servicetalk/buffer/api/Matchers.java
@@ -43,9 +43,6 @@ public final class Matchers {
 
             @Override
             protected boolean matchesSafely(final CharSequence item) {
-                if (item == null) {
-                    return false;
-                }
                 return contentEquals(expected, item);
             }

@kashike thanks for your contribution!!
The rest looks good to me.

@kashike kashike force-pushed the feature/junit-5/buffer-api branch from c0f24d9 to 4278998 Compare May 31, 2021 18:07
Copy link
Contributor

@tkountis tkountis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kashike, last change and we can merge it.

diff --git a/servicetalk-buffer-api/src/test/java/io/servicetalk/buffer/api/AsciiBufferTest.java b/servicetalk-buffer-api/src/test/java/io/servicetalk/buffer/api/AsciiBufferTest.java
index 0acc88708..8c248834c 100644
--- a/servicetalk-buffer-api/src/test/java/io/servicetalk/buffer/api/AsciiBufferTest.java
+++ b/servicetalk-buffer-api/src/test/java/io/servicetalk/buffer/api/AsciiBufferTest.java
@@ -30,7 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-public class AsciiBufferTest {
+class AsciiBufferTest {
     @Test
     void testHashCode() {
         for (int i = 0; i < 1000; ++i) {
diff --git a/servicetalk-buffer-api/src/test/java/io/servicetalk/buffer/api/BufferInputStreamTest.java b/servicetalk-buffer-api/src/test/java/io/servicetalk/buffer/api/BufferInputStreamTest.java
index db31beb03..cccdaa7ff 100644
--- a/servicetalk-buffer-api/src/test/java/io/servicetalk/buffer/api/BufferInputStreamTest.java
+++ b/servicetalk-buffer-api/src/test/java/io/servicetalk/buffer/api/BufferInputStreamTest.java
@@ -25,7 +25,7 @@ import static java.nio.charset.StandardCharsets.US_ASCII;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
 
-public class BufferInputStreamTest {
+class BufferInputStreamTest {
 
     private static final String DATA = "12345";
     private final InputStream is = new BufferInputStream(DEFAULT_RO_ALLOCATOR.fromAscii("12345"));
diff --git a/servicetalk-buffer-api/src/test/java/io/servicetalk/buffer/api/CharSequencesTest.java b/servicetalk-buffer-api/src/test/java/io/servicetalk/buffer/api/CharSequencesTest.java
index 449a8be71..b990d5e03 100644
--- a/servicetalk-buffer-api/src/test/java/io/servicetalk/buffer/api/CharSequencesTest.java
+++ b/servicetalk-buffer-api/src/test/java/io/servicetalk/buffer/api/CharSequencesTest.java
@@ -31,7 +31,7 @@ import static org.hamcrest.Matchers.contains;
 import static org.hamcrest.Matchers.is;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
-public class CharSequencesTest {
+class CharSequencesTest {
 
     // Common strings
     public static final String GZIP = "gzip";
diff --git a/servicetalk-buffer-api/src/test/java/io/servicetalk/buffer/api/ReadOnlyByteBufferTest.java b/servicetalk-buffer-api/src/test/java/io/servicetalk/buffer/api/ReadOnlyByteBufferTest.java
index bb6e52d79..af85b7ca4 100644
--- a/servicetalk-buffer-api/src/test/java/io/servicetalk/buffer/api/ReadOnlyByteBufferTest.java
+++ b/servicetalk-buffer-api/src/test/java/io/servicetalk/buffer/api/ReadOnlyByteBufferTest.java
@@ -25,7 +25,7 @@ import static java.nio.charset.StandardCharsets.US_ASCII;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
-public class ReadOnlyByteBufferTest {
+class ReadOnlyByteBufferTest {
     @Test
     void directFromString() {
         String expectedString = "testing";

Motivation:

- JUnit 5 leverages features from Java 8 or later, such as lambda functions, making tests more powerful and easier to maintain.
- JUnit 5 has added some very useful new features for describing, organizing, and executing tests. For instance, tests get better display names and can be organized hierarchically.
- JUnit 5 is organized into multiple libraries, so only the features you need are imported into your project. With build systems such as Maven and Gradle, including the right libraries is easy.
- JUnit 5 can use more than one extension at a time, which JUnit 4 could not (only one runner could be used at a time). This means you can easily combine the Spring extension with other extensions (such as your own custom extension).

Modifications:

- Unit tests have been migrated from JUnit 4 to JUnit 5

Result:

Module servicetalk-buffer-api now runs tests using JUnit 5
@kashike kashike force-pushed the feature/junit-5/buffer-api branch from 4278998 to 672db3f Compare June 1, 2021 10:45
@kashike
Copy link
Contributor Author

kashike commented Jun 1, 2021

Done @tkountis.

@tkountis tkountis merged commit d89a9a8 into apple:main Jun 1, 2021
@tkountis
Copy link
Contributor

tkountis commented Jun 1, 2021

🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants