-
-
Notifications
You must be signed in to change notification settings - Fork 117
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 to JUnit 5 #135
Migrate to JUnit 5 #135
Conversation
WalkthroughWalkthroughThe recent updates involve a significant migration from JUnit 4 to JUnit 5 across multiple test classes in the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant TestSuite
participant JUnit5
User->>TestSuite: Execute Tests
TestSuite->>JUnit5: Run Test Cases
JUnit5-->>TestSuite: Return Results
TestSuite-->>User: Display Results
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (1)
src/test/java/org/joda/money/TestCurrencyUnit.java (1)
Line range hint
523-552
:
Security warning: Avoid usingObjectInputStream
.The use of
ObjectInputStream
can lead to security vulnerabilities such as remote code execution. Consider safer alternatives or ensure the data being deserialized is trusted.- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); + // Consider using a safer deserialization mechanism or validating the input data.Also applies to: 556-573
Tools
ast-grep
[warning] 541-541: Avoid using ObjectInputStream, it is insecure and can lead to remote code execution
Context: new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))
Note: [CWE-502]: Deserialization of Untrusted Data [OWASP A08:2017]: Insecure Deserialization [OWASP A08:2021]: Software and Data Integrity Failures [REFERENCES]
- https://www.owasp.org/index.php/Deserialization_of_untrusted_data
- https://www.oracle.com/java/technologies/javase/seccodeguide.html#8
[warning] 562-562: Avoid using ObjectInputStream, it is insecure and can lead to remote code execution
Context: new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))
Note: [CWE-502]: Deserialization of Untrusted Data [OWASP A08:2017]: Insecure Deserialization [OWASP A08:2021]: Software and Data Integrity Failures [REFERENCES]
- https://www.owasp.org/index.php/Deserialization_of_untrusted_data
- https://www.oracle.com/java/technologies/javase/seccodeguide.html#8
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (13)
- pom.xml (2 hunks)
- src/test/java/org/joda/money/TestCurrencyMismatchException.java (2 hunks)
- src/test/java/org/joda/money/TestCurrencyUnit.java (27 hunks)
- src/test/java/org/joda/money/TestCurrencyUnitExtension.java (6 hunks)
- src/test/java/org/joda/money/TestIllegalCurrencyException.java (1 hunks)
- src/test/java/org/joda/money/TestMoneyUtils_BigMoney.java (8 hunks)
- src/test/java/org/joda/money/TestMoneyUtils_Money.java (7 hunks)
- src/test/java/org/joda/money/TestStringConvert.java (1 hunks)
- src/test/java/org/joda/money/format/TestMoneyAmountStyle.java (23 hunks)
- src/test/java/org/joda/money/format/TestMoneyFormatter.java (11 hunks)
- src/test/java/org/joda/money/format/TestMoneyFormatterBuilder.java (18 hunks)
- src/test/java/org/joda/money/format/TestMoneyFormatterException.java (1 hunks)
- src/test/java/org/joda/money/format/TestMoneyParseContext.java (3 hunks)
Additional context used
ast-grep
src/test/java/org/joda/money/TestCurrencyUnit.java
[warning] 541-541: Avoid using ObjectInputStream, it is insecure and can lead to remote code execution
Context: new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))
Note: [CWE-502]: Deserialization of Untrusted Data [OWASP A08:2017]: Insecure Deserialization [OWASP A08:2021]: Software and Data Integrity Failures [REFERENCES]
- https://www.owasp.org/index.php/Deserialization_of_untrusted_data
- https://www.oracle.com/java/technologies/javase/seccodeguide.html#8
[warning] 562-562: Avoid using ObjectInputStream, it is insecure and can lead to remote code execution
Context: new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))
Note: [CWE-502]: Deserialization of Untrusted Data [OWASP A08:2017]: Insecure Deserialization [OWASP A08:2021]: Software and Data Integrity Failures [REFERENCES]
- https://www.owasp.org/index.php/Deserialization_of_untrusted_data
- https://www.oracle.com/java/technologies/javase/seccodeguide.html#8
Additional comments not posted (53)
src/test/java/org/joda/money/format/TestMoneyFormatterException.java (5)
18-19
: Good use of JUnit 5 assertions.The transition to
assertThrows
andassertDoesNotThrow
enhances clarity and aligns with modern testing practices.
23-23
: JUnit 5 annotation update is appropriate.Updating the
@Test
annotation to JUnit 5 is a necessary step in the migration process.
28-28
: Visibility reduction is appropriate for test classes.Changing the class to package-private is a good practice as test classes do not need to be public.
30-33
: Correct use ofassertThrows
.Replacing the
expected
parameter withassertThrows
improves the readability and clarity of the test.
37-39
: Correct use ofassertDoesNotThrow
.Using
assertDoesNotThrow
appropriately checks that no exception is thrown, improving test clarity.src/test/java/org/joda/money/TestIllegalCurrencyException.java (5)
18-19
: Good transition to JUnit 5 assertions.Switching to
assertEquals
andassertNull
from JUnit 5 improves the clarity and functionality of the tests.
21-21
: JUnit 5 annotation update is appropriate.Updating the
@Test
annotation to JUnit 5 is a necessary step in the migration process.
26-26
: Visibility reduction is appropriate for test classes.Changing the class to package-private is a good practice as test classes do not need to be public.
32-35
: Use ofassertNull
is semantically appropriate.Replacing
assertEquals
withassertNull
for null checks is a more semantically correct approach.
39-42
: Appropriate use ofassertNull
for null checks.Using
assertNull
for both message and cause checks improves test clarity and correctness.src/test/java/org/joda/money/TestStringConvert.java (6)
18-18
: Good transition to JUnit 5 assertions.Switching to
assertEquals
from JUnit 5 improves the clarity and functionality of the tests.
22-22
: JUnit 5 annotation update is appropriate.Updating the
@Test
annotation to JUnit 5 is a necessary step in the migration process.
27-27
: Visibility reduction is appropriate for test classes.Changing the class to package-private is a good practice as test classes do not need to be public.
30-33
: Correct parameter order inassertEquals
.Ensuring the expected value is first in
assertEquals
calls aligns with best practices.
38-41
: Correct parameter order inassertEquals
.Ensuring the expected value is first in
assertEquals
calls aligns with best practices.
46-49
: Correct parameter order inassertEquals
.Ensuring the expected value is first in
assertEquals
calls aligns with best practices.src/test/java/org/joda/money/TestCurrencyMismatchException.java (4)
18-19
: Update imports to JUnit 5.The import statements have been correctly updated to use JUnit 5's
Assertions
class. This change aligns with modern testing practices.
21-21
: Use of JUnit 5 @test annotation.The
@Test
annotation is now sourced fromorg.junit.jupiter.api.Test
, which is appropriate for JUnit 5.
26-26
: Visibility change for the test class.The class
TestCurrencyMismatchException
has been changed frompublic
to package-private. This is generally acceptable for test classes unless they need to be accessed from other packages.Ensure that this change does not affect any external test runners or frameworks that might require public visibility.
35-67
: Improved assertion methods.The assertions have been updated to use
assertNull
, which improves readability and aligns with JUnit 5 best practices. The method visibility has been changed to package-private, which is consistent with JUnit 5 conventions.src/test/java/org/joda/money/TestCurrencyUnitExtension.java (4)
18-20
: Update imports to JUnit 5.The import statements have been correctly updated to use JUnit 5's
Assertions
class. This change aligns with modern testing practices.
24-24
: Use of JUnit 5 @test annotation.The
@Test
annotation is now sourced fromorg.junit.jupiter.api.Test
, which is appropriate for JUnit 5.
29-29
: Visibility change for the test class.The class
TestCurrencyUnitExtension
has been changed frompublic
to package-private. This is generally acceptable for test classes unless they need to be accessed from other packages.Ensure that this change does not affect any external test runners or frameworks that might require public visibility.
Line range hint
32-94
:
Improved assertion methods.The assertions have been updated to use
assertTrue
, which improves readability and aligns with JUnit 5 best practices. The method visibility has been changed to package-private, which is consistent with JUnit 5 conventions.src/test/java/org/joda/money/format/TestMoneyParseContext.java (4)
18-21
: Update imports to JUnit 5.The import statements have been correctly updated to use JUnit 5's
Assertions
class. This change aligns with modern testing practices.
28-28
: Use of JUnit 5 @test annotation.The
@Test
annotation is now sourced fromorg.junit.jupiter.api.Test
, which is appropriate for JUnit 5.
33-33
: Visibility change for the test class.The class
TestMoneyParseContext
has been changed frompublic
to package-private. This is generally acceptable for test classes unless they need to be accessed from other packages.Ensure that this change does not affect any external test runners or frameworks that might require public visibility.
Line range hint
36-143
:
Improved assertion methods and exception testing.The assertions have been updated to use
assertNull
,assertFalse
, andassertThrows
, which improve readability and align with JUnit 5 best practices. The method visibility has been changed to package-private, which is consistent with JUnit 5 conventions.src/test/java/org/joda/money/TestMoneyUtils_BigMoney.java (5)
18-23
: Update to JUnit 5 imports looks good.The transition to JUnit 5 assertions is correctly implemented. This change enhances the test suite's compatibility with modern testing practices.
28-28
: JUnit 5@Test
annotation is correctly used.The import statement for
@Test
has been updated to JUnit 5, which is appropriate for the migration.
33-33
: Visibility change to package-private is appropriate.Changing the class visibility from
public
to package-private is a good practice for test classes, as they do not need to be exposed outside their package.
47-47
: Test method visibility change is appropriate.Changing the method visibility to package-private is consistent with JUnit 5 practices and helps encapsulate the test logic within the package.
123-126
: Use ofassertThrows
for exception testing is correct.The use of
assertThrows
enhances readability and aligns with JUnit 5's approach to exception testing.src/test/java/org/joda/money/TestMoneyUtils_Money.java (5)
18-23
: Update to JUnit 5 imports looks good.The transition to JUnit 5 assertions is correctly implemented. This change enhances the test suite's compatibility with modern testing practices.
25-25
: JUnit 5@Test
annotation is correctly used.The import statement for
@Test
has been updated to JUnit 5, which is appropriate for the migration.
30-30
: Visibility change to package-private is appropriate.Changing the class visibility from
public
to package-private is a good practice for test classes, as they do not need to be exposed outside their package.
49-57
: Use ofassertThrows
for exception testing is correct.The use of
assertThrows
enhances readability and aligns with JUnit 5's approach to exception testing.
129-132
: Use ofassertThrows
for exception testing is correct.The use of
assertThrows
enhances readability and aligns with JUnit 5's approach to exception testing.src/test/java/org/joda/money/format/TestMoneyFormatter.java (5)
18-22
: Update to JUnit 5 imports looks good.The transition to JUnit 5 assertions is correctly implemented. This change enhances the test suite's compatibility with modern testing practices.
37-41
: Lifecycle and parameterized test annotations are correctly updated.The use of
@BeforeEach
,@AfterEach
,@ParameterizedTest
, and@MethodSource
aligns with JUnit 5's practices, enhancing test setup and flexibility.
46-46
: Visibility change to package-private is appropriate.Changing the class visibility from
public
to package-private is a good practice for test classes, as they do not need to be exposed outside their package.
58-58
: Method visibility change to package-private is appropriate.Changing the method visibility to package-private is consistent with JUnit 5 practices and helps encapsulate the test logic within the package.
125-127
: Use ofassertThrows
for exception testing is correct.The use of
assertThrows
enhances readability and aligns with JUnit 5's approach to exception testing.src/test/java/org/joda/money/TestCurrencyUnit.java (2)
18-21
: Imports updated to JUnit 5.The import statements have been correctly updated to use JUnit 5 assertions and annotations.
Also applies to: 37-37
73-77
: Use ofassertThrows
for exception testing.The use of
assertThrows
is a good practice in JUnit 5 for testing exceptions. It improves readability and clarity.pom.xml (1)
523-524
: JUnit 5 dependency update.The dependencies for JUnit have been correctly updated to JUnit 5.11.0. The removal of
junit-dataprovider
is consistent with moving to JUnit 5's built-in parameterized testing capabilities.Also applies to: 789-789
src/test/java/org/joda/money/format/TestMoneyFormatterBuilder.java (3)
18-22
: Imports updated to JUnit 5.The import statements have been correctly updated to use JUnit 5 assertions, annotations, and parameterized test features.
Also applies to: 33-37
66-67
: Lifecycle annotations updated to JUnit 5.The
@BeforeEach
and@AfterEach
annotations are correctly used to handle setup and teardown, replacing JUnit 4's@Before
and@After
.Also applies to: 72-73
372-374
: Transition to@ParameterizedTest
.The use of
@ParameterizedTest
with@MethodSource
is a modern and flexible way to handle parameterized tests in JUnit 5.Also applies to: 418-420, 619-621, 637-639, 655-657, 698-700
src/test/java/org/joda/money/format/TestMoneyAmountStyle.java (4)
18-23
: Import changes approved.The import statements have been correctly updated to use JUnit 5's
org.junit.jupiter.api
package. This is consistent with the migration objectives.Also applies to: 30-32
37-51
: Class and lifecycle method changes approved.The class visibility and lifecycle annotations have been correctly updated to JUnit 5 standards. The transition from
@Before
and@After
to@BeforeEach
and@AfterEach
is appropriate.
Line range hint
59-822
:
Test method and assertion changes approved.The test methods have been updated with JUnit 5 assertions, enhancing readability and maintainability. The change in method visibility to package-private is also consistent with JUnit 5 practices.
589-594
: Exception handling change approved.The use of
assertThrows
for testing exceptions is a correct and modern approach in JUnit 5.
Summary by CodeRabbit
New Features
Bug Fixes
assertThrows
andassertDoesNotThrow
for clearer exception handling.Refactor
public
access modifier from test methods to follow best practices in JUnit 5.Documentation
These changes collectively modernise the testing framework and improve the robustness of our test suite.