[ 
https://issues.apache.org/jira/browse/IO-628?focusedWorklogId=320845&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-320845
 ]

ASF GitHub Bot logged work on IO-628:
-------------------------------------

                Author: ASF GitHub Bot
            Created on: 30/Sep/19 20:40
            Start Date: 30/Sep/19 20:40
    Worklog Time Spent: 10m 
      Work Description: mureinik commented on pull request #97: IO-628: 
Migration to JUnit Jupiter
URL: https://github.com/apache/commons-io/pull/97
 
 
   This PR upgrades the project's testing framework from JUnit 4.12 to the 
modern JUnit Jupiter 5.5.4.
   
   Since JUnit 5 Jupiter is not backwards compatible to JUnit 4.x (or even 
JUnit Vintage), this PR is a bit large, even though a lot of the changes are 
merely cosmetic (such as changing the argument order,
   see details below). In order to make the reviewer's task as easy as 
possible, this PR does not presume to use JUnit Jupiter's best practices and 
all its new functionality, but only to migrate the existing tests with as 
little change as possible. Following PRs may want to improve the tests by using 
some of JUnit Jupiter's new  features.
   
   This patch includes the following changes:
   
   1. Maven dependency changes:
       1. `junit:junit` was replaced with `org.junit.jupiter:junit-jupiter`.
       1. `org.junit-pioneer:junit-pioneer` was introduced (see details below 
in section 2.vii.).
   
   2. Annotations:
       1. `org.junit.jupiter.api.Test` was used as a drop in replacement for 
`org.juit.Test` without arguments. See 3.ii. and 3.iii. for handling of `@Test` 
annotations with `expected` and `timeout` arguments respectively.
       1. `org.junit.jupiter.params.ParameterizedTest` in conjunction with 
`org.junit.jupiter.params.provider.MethodSource` was used to replace 
`org.juit.Test` in test classes run with `org.junit.runners.Parameterized`.
       1. `org.junit.runners.Parameterized.Parameters` annotations were 
removed, and the methods annotated with them were written to match the 
signature expected of a `@MethodSource`.
       1. `org.junit.jupiter.api.BeforeEach` was used as an drop in replacement 
for `org.junit.Before`.
       1. `org.junit.jupiter.api.AfterEach` was used as a drop in replacement 
for `org.junit.After`.
       1. `org.junit.jupiter.api.Disabled` was used as a drop in replacement 
for `org.junit.Ignore`.
       1. `org.junitpioneer.jupiter.DefaultLocale` was used as a drop in 
replacement for `org.apache.commons.io.testtools.SystemDefaults`. This 
annotation comes from the JUnit Pioneer project, and while it isn't part of the 
actual JUnit project, it's widely accepted as an extension library for JUnit, 
and is used in other Apache Commons projects, such as Apache Commons Lang.
   
   3. Assertions:
       1. `org.junit.jupiter.api.Assertions`' methods were used as drop in 
replacements for `org.junit.Assert`'s methods with the same name in the simple 
case of an assertion without a message.  In the case of an assertion with a 
message, `org.junit.jupiter.api.Assertions`' methods were used, but the 
argument order was changed - `Assert`'s methods take the message as the first 
argument, while `Assertions`' methods take the message as the last argument.
       1. `org.junit.jupiter.api.Assertions#assertThrows` was used to assert 
that a specific exception was throws instead of an `org.junit.Test` annotation 
with an `expected` argument. This technique has a side bonus of making the 
tests slightly stricter, as now they can assert the exception was thrown from a 
specific line and prevent false positives where the test's "set-up" code 
accidentally threw that exception. The `throws` clauses of these methods were 
cleaned up from exceptions that can no longer be thrown in order to avoid 
compilation warnings.
       1. `org.junit.jupiter.api.Assertions#assertTimeout` was used to assert a 
specific block of code completes before a timeout is reach instead of an 
`org.junit.Test` annotation with a `timeout` argument.
       1. `org.junit.jupiter.api.Assertions#fail` was used in order to 
explicitly fail a test instead of throwing a 
`junit.framework.AssertionFailedError`.
   
   4. Assumptions
       1. `org.junit.jupiter.api.Assumptions`' methods were used as drop in 
replacements for `org.junit.Assume`'s methods with the same name, but the 
argument order was changed - `Assume`'s methods take the message as the first 
argument, while `Assumptions`' methods take the message as the last argument.
   
   5. Rules
       1. `org.junit.jupiter.api.io.TempDir` was used instead of the 
`org.junit.rules.TemporaryFolder` `@Rule`, and the code that used them was 
adapted accordingly. Note that `TempDir` is stricter than the old 
`TemporaryFolder` rule, and will fail the test if any file in the temporary 
directory cannot be deleted. `TailerTest` opens multiple threads that hold open 
descriptors on files in the temporary directory which prevent their deletion 
(at least in Windows), and would fail the test when migrated to `@TempDir`. 
These threads had to be explicitly closed in order to allow the tests to pass.
       1. `org.apache.commons.io.testtools.SystemDefaultsSwitch` was removed 
from the project, and its functionality replaced by 
`org.junitpioneer.jupiter.DefaultLocale`.
   
   
   6. Specific changes:
       1. Parameters in JUnit Jupiter (such as those produced by 
`MethodSource`) can only be applied to `@Test` methods, not to other lifecycle 
methods, such as `@BeforeEach`. Thus, the design of 
`ReversedLinesFileReaderTestParamFile` had to be changed - instead of receiving 
constructor arguments and storing a state in data members, it was rewritten to 
be stateless, and manage all its resources in the single test method it has, 
`testDataIntegrityWithBufferedReader`. As a side bonus, this change allows to 
narrow the scope of open resources, and close them immediately after they are 
no longer needed, instead of preserving them in data members until the `@After` 
method is called.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

            Worklog Id:     (was: 320845)
    Remaining Estimate: 0h
            Time Spent: 10m

> Migration Commons-IO to JUnit Jupiter
> -------------------------------------
>
>                 Key: IO-628
>                 URL: https://issues.apache.org/jira/browse/IO-628
>             Project: Commons IO
>          Issue Type: Task
>          Components: Utilities
>            Reporter: Allon Mureinik
>            Priority: Minor
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Migrate the Commons IO project to the modern JUnit Jupiter framework (instead 
> of JUnit 4 which it currently uses) in order to make it easier to maintain 
> and for future contributors to participate.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to