Skip to content

Replace JUnit 3 with JUnit 5#344

Merged
garydgregory merged 2 commits intoapache:masterfrom
theobisproject:replace-junit3
Dec 27, 2022
Merged

Replace JUnit 3 with JUnit 5#344
garydgregory merged 2 commits intoapache:masterfrom
theobisproject:replace-junit3

Conversation

@theobisproject
Copy link
Contributor

Most tests are replaced with simple JUnit 5 tests. A small number of tests were migrated to parameterized tests.

@codecov-commenter
Copy link

codecov-commenter commented Dec 26, 2022

Codecov Report

Merging #344 (c202c30) into master (f6dadd2) will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##             master     #344   +/-   ##
=========================================
  Coverage     80.33%   80.33%           
  Complexity     6653     6653           
=========================================
  Files           342      342           
  Lines         25232    25232           
  Branches       4085     4085           
=========================================
  Hits          20271    20271           
  Misses         3382     3382           
  Partials       1579     1579           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

try {
checkArchiveContent(ais, expected);
} catch (final AssertionFailedError e) {
} catch (final Exception e) {
Copy link
Member

@garydgregory garydgregory Dec 26, 2022

Choose a reason for hiding this comment

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

-1: Porting to JUnit 5 means using Assertions.assertThrows(), Assertions.doesNotThrow(), and so on, not whatever this is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm with you on this one (and the one in the LongSymLinkTest). Just did not want to do too much in one go.

If I understand the test correctly we can get rid of the try-catch block completely since we do not want the check to throw an exception.

@garydgregory
Copy link
Member

Hi @theobisproject
Thank you for pitching in!
No matter which way you slice it, it's going to be a large PR. The only way I can think of making it smaller is by doing it one package at a time. Whichever way you go, I'd rather see it all done the "JUnit 5 way" rather than something in between.

@theobisproject
Copy link
Contributor Author

@garydgregory I will go through the classes and do some more migrations. Is there anything else you would like to have changed (like using try-with-resources, ...)?

@garydgregory
Copy link
Member

Keep it focused on the one task please: Junit 5 😉

@theobisproject
Copy link
Contributor Author

I have replaced all the try-catch-assert patterns in the tests I migrated. Also more tests do now use the parameterized tests for execution.

import org.junit.jupiter.params.provider.MethodSource;

public class ArchiveTest extends TestCase {
class ArchiveTest {
Copy link
Member

@garydgregory garydgregory Dec 26, 2022

Choose a reason for hiding this comment

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

There is no need to change the visibility of elements, it just overloads the PR with noise for no gain. Yes, I know that JUnit 5 like this style, but that is not the style we use in most if not all of Conmons components. It just make the PR harder and longer to review. What matters is the use of the Junit API, not the style IMO. For my money, the fact that a test is public tells me it's important, not some internal gadget, so let's not change access unless required (which should not happen).

Copy link
Member

@garydgregory garydgregory left a comment

Choose a reason for hiding this comment

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

See comments. TY!


public void testAlternativeConstructor() throws IOException, URISyntaxException, Pack200Exception {
@Test
void testAlternativeConstructor() throws IOException, URISyntaxException, Pack200Exception {
Copy link
Member

Choose a reason for hiding this comment

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

See above.


public void testAnnotations() throws IOException, Pack200Exception,
@Test
void testAnnotations() throws IOException, Pack200Exception,
Copy link
Member

Choose a reason for hiding this comment

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

See above.


public void testAnnotations2() throws IOException, Pack200Exception,
@Test
void testAnnotations2() throws IOException, Pack200Exception,
Copy link
Member

Choose a reason for hiding this comment

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

And so on, so I'll stop here.

Most tests are replaced with simple JUnit 5 tests. A small number of tests were migrated to parameterized tests.
- Replace try-catch-assert with assertThrows/assertDoesNotThrow
- Migrate more tests to use the parameterized test execution
@theobisproject
Copy link
Contributor Author

I have removed the visibility change of the classes and methods from the commits.

@garydgregory garydgregory merged commit 0bc7f12 into apache:master Dec 27, 2022
garydgregory added a commit that referenced this pull request Dec 27, 2022
@theobisproject theobisproject deleted the replace-junit3 branch December 27, 2022 23:02
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.

3 participants