Commit eae791d
IO-628: Migration to JUnit Jupiter (#97)
* Use fail instead of throwing an AssertionFailedError
Use JUnit's Assert#fail in order to fail tests with the proper JUnit
API, instead of explicitly throwing the underlying exception.
This change makes the tests easier to read and maintain, and will help
facilitate the migration to JUnit Jupiter.
* Remove outdate javadoc references to TestCase#setUp()
In JUnit 3, in order to run some code before each test, you would
extend junit.framework.TestCase and override its setUp() method.
In JUnit 4 this is no longer the case, and you simply need to annotate
the method with org.junit.Before, as is done in the classes in
question.
This patch removes old javadoc comments that reference the TestCase
method which are no longer relevant, and are probably outdated remains
from the days the project used JUnit 3.
* Standardize org.junit.Assert imports
The de-facto standard for using org.junit.Assert methods in the
project is to statically import its method.
However, some places use the class directly and call methods on it.
This patch standardizes the approach, and makes sure all the usages of
org.junit.Assert statically import methods in order to have a
consistent coding standard throughout the project's tests.
* Statically import org.junit.Assume methods
Statically import methods from org.junit.Assume in order to make its
usages consistent with org.junit.Assert's usage pattern.
* Migrate test suite to JUnit Jupiter
This patch 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 patch 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 patch does not presume to use JUnit Jupiter's best
practices and all its new functionality, but only to migrate the
existing test with as little change as possible. Following patches
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:
a. junit:junit was replaced with org.junit.jupiter:junit-jupiter.
b. org.junit-pioneer:junit-pioneer was introduced (see details
below in section 2.g.).
2. Annotations:
a. org.junit.jupiter.api.Test was used as a drop in replacement for
org.juit.Test without arguments. See 3.b. and 3.c. for handling
of @test annotations with "expected" and "timeout" arguments
respectively.
b. 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.
c. org.junit.runners.Parameterized.Parameters annotations were
removed, and the methods annotated with them were written to
match the signature expected of a @MethodSource
d. org.junit.jupiter.api.BeforeEach was used as an drop in
replacement for org.junit.Before.
e. org.junit.jupiter.api.AfterEach was used as a drop in replacement
for org.junit.After.
f. org.junit.jupiter.api.Disabled was used as a drop in replacement
for org.junit.Ignore.
g. 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:
a. 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.
b. 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.
c. 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.
4. Assumptions
a. 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
a. 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.
b. org.apache.commons.io.testtools.SystemDefaultsSwitch was removed
from the project, and its functionality replaced by
org.junitpioneer.jupiter.DefaultLocale.
6. Specific changes:
a. 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.
b. JUnit Jupiter's @tempdir is stricter than JUnit 4's
@TemporaryFolder, and if it cannot delete any file at the end of
the test, it will fail the test. FileUtilsCleanDirectoryTestCase's
methods testThrowsOnNullList and testThrowsOnCannotDeleteFile
chmod the temporary directory and thus prevent files in it from
being deleted at the end of the test. A finally block was added to
these tests in order to chmod the temporary directory back to 755
and allow it to be deleted. In addition, the restriction of not
running the test on Windows was changed to use JUnit Jupiter's
@DisabledOnOs annotation, in order to make the test a tad easier
to follow.
c. TailerTest has a similar issue to 6.b., where threads opened
during the test are only closed in the @AfterEach method (by
calling Tailer#stop), which is too late, since the @tempdir's
tear down is called (and fails) before hand. Using a shared temp
dir (by declaring the member static) causes the directory to be
deleted only when the entire class is finished.
* Attempt to disable JaCoCo for JDK EA
This is done by passing an environment variable in the .travis.yml
file, and then using it to set the jacoco.skip property in the
pom.xml.1 parent 8940848 commit eae791d
130 files changed
Lines changed: 2375 additions & 2631 deletions
File tree
- src/test/java/org/apache/commons/io
- comparator
- filefilter
- input
- buffer
- monitor
- output
- serialization
- testtools
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
26 | 34 | | |
27 | 35 | | |
28 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
230 | | - | |
231 | | - | |
232 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
233 | 239 | | |
234 | 240 | | |
235 | 241 | | |
| |||
285 | 291 | | |
286 | 292 | | |
287 | 293 | | |
| 294 | + | |
288 | 295 | | |
289 | 296 | | |
290 | 297 | | |
| |||
Lines changed: 37 additions & 36 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
47 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | | - | |
64 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
81 | | - | |
82 | | - | |
83 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
105 | | - | |
106 | | - | |
107 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
| |||
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
142 | | - | |
143 | | - | |
144 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
145 | 146 | | |
146 | 147 | | |
Lines changed: 9 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | | - | |
22 | | - | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | | - | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
37 | | - | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | | - | |
41 | | - | |
42 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
43 | 45 | | |
44 | 46 | | |
Lines changed: 19 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
23 | | - | |
24 | | - | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
48 | | - | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | | - | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
66 | | - | |
| 67 | + | |
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
71 | | - | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
76 | | - | |
| 77 | + | |
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
81 | | - | |
| 82 | + | |
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
0 commit comments