2929import java .util .List ;
3030import java .util .Set ;
3131
32- import org .junit .Before ;
33- import org .junit .Rule ;
34- import org .junit .Test ;
35- import org .junit .rules .TestName ;
32+ import org .junit .jupiter .api .BeforeEach ;
33+ import org .junit .jupiter .api .Test ;
34+ import org .junit .jupiter .api .TestInfo ;
3635
37- import static org .junit .Assert .assertEquals ;
38- import static org .junit .Assert .assertFalse ;
39- import static org .junit .Assert .assertTrue ;
40- import static org .junit .Assert .fail ;
41- import static org .junit .Assume .assumeTrue ;
36+ import static org .junit .jupiter . api . Assertions .assertEquals ;
37+ import static org .junit .jupiter . api . Assertions .assertFalse ;
38+ import static org .junit .jupiter . api . Assertions .assertTrue ;
39+ import static org .junit .jupiter . api . Assertions .fail ;
40+ import static org .junit .jupiter . api . Assumptions .assumeTrue ;
4241
4342/**
4443 * Base class for testcases doing tests with files.
4847 * @since 3.4.0
4948 */
5049public class DirectoryScannerTest extends FileBasedTestCase {
51- @ Rule
52- public TestName name = new TestName ();
5350
54- private static String testDir = getTestDirectory ().getPath ();
51+ public String name ;
52+
53+ private static final String testDir = getTestDirectory ().getPath ();
5554
5655 /**
5756 * <p>setUp.</p>
5857 */
59- @ Before
60- public void setUp () {
58+ @ BeforeEach
59+ void setUp (TestInfo testInfo ) {
60+ testInfo .getTestMethod ().ifPresent (method -> this .name = method .getName ());
6161 try {
6262 FileUtils .deleteDirectory (testDir );
6363 } catch (IOException e ) {
@@ -72,7 +72,7 @@ public void setUp() {
7272 * @throws java.net.URISyntaxException if any.
7373 */
7474 @ Test
75- public void testCrossPlatformIncludesString () throws IOException , URISyntaxException {
75+ void crossPlatformIncludesString () throws IOException , URISyntaxException {
7676 DirectoryScanner ds = new DirectoryScanner ();
7777 ds .setBasedir (new File (getTestResourcesDir () + File .separator + "directory-scanner" ).getCanonicalFile ());
7878
@@ -98,7 +98,7 @@ public void testCrossPlatformIncludesString() throws IOException, URISyntaxExcep
9898 * @throws java.net.URISyntaxException if any.
9999 */
100100 @ Test
101- public void testCrossPlatformExcludesString () throws IOException , URISyntaxException {
101+ void crossPlatformExcludesString () throws IOException , URISyntaxException {
102102 DirectoryScanner ds = new DirectoryScanner ();
103103 ds .setBasedir (new File (getTestResourcesDir () + File .separator + "directory-scanner" ).getCanonicalFile ());
104104 ds .setIncludes (new String [] {"**" });
@@ -161,11 +161,10 @@ private boolean checkTestFilesSymlinks() {
161161 }
162162 return true ;
163163 } catch (IOException e ) {
164- System .err .println (String .format (
165- "The unit test '%s.%s' will be skipped, reason: %s" ,
166- this .getClass ().getSimpleName (), name .getMethodName (), e .getMessage ()));
167- System .out .println (
168- String .format ("This test requires symlinks files in '%s' directory." , symlinksDirectory .getPath ()));
164+ System .err .printf (
165+ "The unit test '%s.%s' will be skipped, reason: %s%n" ,
166+ this .getClass ().getSimpleName (), name , e .getMessage ());
167+ System .out .printf ("This test requires symlinks files in '%s' directory.%n" , symlinksDirectory .getPath ());
169168 System .out .println ("On some OS (like Windows 10), files are present only if the clone/checkout is done"
170169 + " in administrator mode, and correct (symlinks and not flat file/directory)"
171170 + " if symlinks option are used (for git: git clone -c core.symlinks=true [url])" );
@@ -179,18 +178,18 @@ private boolean checkTestFilesSymlinks() {
179178 * @throws java.io.IOException if any.
180179 */
181180 @ Test
182- public void testGeneral () throws IOException {
181+ void general () throws IOException {
183182 this .createTestFiles ();
184183
185184 String includes = "scanner1.dat,scanner2.dat,scanner3.dat,scanner4.dat,scanner5.dat" ;
186185 String excludes = "scanner1.dat,scanner2.dat" ;
187186
188187 List <File > fileNames = FileUtils .getFiles (new File (testDir ), includes , excludes , false );
189188
190- assertEquals ("Wrong number of results." , 3 , fileNames . size () );
191- assertTrue ("3 not found." , fileNames .contains (new File ("scanner3.dat" )));
192- assertTrue ("4 not found." , fileNames .contains (new File ("scanner4.dat" )));
193- assertTrue ("5 not found." , fileNames .contains (new File ("scanner5.dat" )));
189+ assertEquals (3 , fileNames . size (), "Wrong number of results." );
190+ assertTrue (fileNames .contains (new File ("scanner3.dat" )), "3 not found." );
191+ assertTrue (fileNames .contains (new File ("scanner4.dat" )), "4 not found." );
192+ assertTrue (fileNames .contains (new File ("scanner5.dat" )), "5 not found." );
194193 }
195194
196195 /**
@@ -199,7 +198,7 @@ public void testGeneral() throws IOException {
199198 * @throws java.io.IOException if any.
200199 */
201200 @ Test
202- public void testIncludesExcludesWithWhiteSpaces () throws IOException {
201+ void includesExcludesWithWhiteSpaces () throws IOException {
203202 this .createTestFiles ();
204203
205204 String includes = "scanner1.dat,\n \n ,scanner2.dat \n \r , scanner3.dat\n , \t scanner4.dat,scanner5.dat\n ," ;
@@ -208,17 +207,17 @@ public void testIncludesExcludesWithWhiteSpaces() throws IOException {
208207
209208 List <File > fileNames = FileUtils .getFiles (new File (testDir ), includes , excludes , false );
210209
211- assertEquals ("Wrong number of results." , 3 , fileNames . size () );
212- assertTrue ("3 not found." , fileNames .contains (new File ("scanner3.dat" )));
213- assertTrue ("4 not found." , fileNames .contains (new File ("scanner4.dat" )));
214- assertTrue ("5 not found." , fileNames .contains (new File ("scanner5.dat" )));
210+ assertEquals (3 , fileNames . size (), "Wrong number of results." );
211+ assertTrue (fileNames .contains (new File ("scanner3.dat" )), "3 not found." );
212+ assertTrue (fileNames .contains (new File ("scanner4.dat" )), "4 not found." );
213+ assertTrue (fileNames .contains (new File ("scanner5.dat" )), "5 not found." );
215214 }
216215
217216 /**
218217 * <p>testFollowSymlinksFalse.</p>
219218 */
220219 @ Test
221- public void testFollowSymlinksFalse () {
220+ void followSymlinksFalse () {
222221 assumeTrue (checkTestFilesSymlinks ());
223222
224223 DirectoryScanner ds = new DirectoryScanner ();
@@ -253,7 +252,7 @@ private void assertAlwaysIncluded(List<String> included) {
253252 * <p>testFollowSymlinks.</p>
254253 */
255254 @ Test
256- public void testFollowSymlinks () {
255+ void followSymlinks () {
257256 assumeTrue (checkTestFilesSymlinks ());
258257
259258 DirectoryScanner ds = new DirectoryScanner ();
@@ -300,7 +299,7 @@ private void createTestDirectories() throws IOException {
300299 * @throws java.io.IOException if any.
301300 */
302301 @ Test
303- public void testDirectoriesWithHyphens () throws IOException {
302+ void directoriesWithHyphens () throws IOException {
304303 this .createTestDirectories ();
305304
306305 DirectoryScanner ds = new DirectoryScanner ();
@@ -313,7 +312,7 @@ public void testDirectoriesWithHyphens() throws IOException {
313312 ds .scan ();
314313
315314 String [] files = ds .getIncludedFiles ();
316- assertEquals ("Wrong number of results." , 3 , files . length );
315+ assertEquals (3 , files . length , "Wrong number of results." );
317316 }
318317
319318 /**
@@ -322,7 +321,7 @@ public void testDirectoriesWithHyphens() throws IOException {
322321 * @throws java.io.IOException if any.
323322 */
324323 @ Test
325- public void testAntExcludesOverrideIncludes () throws IOException {
324+ void antExcludesOverrideIncludes () throws IOException {
326325 printTestHeader ();
327326
328327 File dir = new File (testDir , "regex-dir" );
@@ -360,7 +359,7 @@ public void testAntExcludesOverrideIncludes() throws IOException {
360359 * @throws java.io.IOException if any.
361360 */
362361 @ Test
363- public void testAntExcludesOverrideIncludesWithExplicitAntPrefix () throws IOException {
362+ void antExcludesOverrideIncludesWithExplicitAntPrefix () throws IOException {
364363 printTestHeader ();
365364
366365 File dir = new File (testDir , "regex-dir" );
@@ -399,7 +398,7 @@ public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() throws IOExce
399398 * @throws java.io.IOException if any.
400399 */
401400 @ Test
402- public void testRegexIncludeWithExcludedPrefixDirs () throws IOException {
401+ void regexIncludeWithExcludedPrefixDirs () throws IOException {
403402 printTestHeader ();
404403
405404 File dir = new File (testDir , "regex-dir" );
@@ -433,7 +432,7 @@ public void testRegexIncludeWithExcludedPrefixDirs() throws IOException {
433432 * @throws java.io.IOException if any.
434433 */
435434 @ Test
436- public void testRegexExcludeWithNegativeLookahead () throws IOException {
435+ void regexExcludeWithNegativeLookahead () throws IOException {
437436 printTestHeader ();
438437
439438 File dir = new File (testDir , "regex-dir" );
@@ -472,7 +471,7 @@ public void testRegexExcludeWithNegativeLookahead() throws IOException {
472471 * @throws java.io.IOException if any.
473472 */
474473 @ Test
475- public void testRegexWithSlashInsideCharacterClass () throws IOException {
474+ void regexWithSlashInsideCharacterClass () throws IOException {
476475 printTestHeader ();
477476
478477 File dir = new File (testDir , "regex-dir" );
@@ -513,7 +512,7 @@ public void testRegexWithSlashInsideCharacterClass() throws IOException {
513512 * @throws java.io.IOException if occurs an I/O error.
514513 */
515514 @ Test
516- public void testDoNotScanUnnecesaryDirectories () throws IOException {
515+ void doNotScanUnnecesaryDirectories () throws IOException {
517516 createTestDirectories ();
518517
519518 // create additional directories 'anotherDir1', 'anotherDir2' and 'anotherDir3' with a 'file1.dat' file
@@ -582,7 +581,7 @@ protected void scandir(File dir, String vpath, boolean fast) {
582581 * @throws java.io.IOException if any.
583582 */
584583 @ Test
585- public void testIsSymbolicLink () throws IOException {
584+ void isSymbolicLink () throws IOException {
586585 assumeTrue (checkTestFilesSymlinks ());
587586
588587 final File directory = new File ("src/test/resources/symlinks/src" );
@@ -599,7 +598,7 @@ public void testIsSymbolicLink() throws IOException {
599598 * @throws java.io.IOException if any.
600599 */
601600 @ Test
602- public void testIsParentSymbolicLink () throws IOException {
601+ void isParentSymbolicLink () throws IOException {
603602 assumeTrue (checkTestFilesSymlinks ());
604603
605604 final File directory = new File ("src/test/resources/symlinks/src" );
0 commit comments