Convert to JUnit 5 with OpenRewrite · codehaus-plexus/plexus-utils@1d4f135 (original) (raw)

`@@ -29,16 +29,15 @@

`

29

29

`import java.util.List;

`

30

30

`import java.util.Set;

`

31

31

``

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;

`

36

35

``

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;

`

42

41

``

43

42

`/**

`

44

43

` * Base class for testcases doing tests with files.

`

`@@ -48,16 +47,17 @@

`

48

47

` * @since 3.4.0

`

49

48

` */

`

50

49

`public class DirectoryScannerTest extends FileBasedTestCase {

`

51

``

`-

@Rule

`

52

``

`-

public TestName name = new TestName();

`

53

50

``

54

``

`-

private static String testDir = getTestDirectory().getPath();

`

``

51

`+

public String name;

`

``

52

+

``

53

`+

private static final String testDir = getTestDirectory().getPath();

`

55

54

``

56

55

`/**

`

57

56

` *

setUp.

`

58

57

` */

`

59

``

`-

@Before

`

60

``

`-

public void setUp() {

`

``

58

`+

@BeforeEach

`

``

59

`+

void setUp(TestInfo testInfo) {

`

``

60

`+

testInfo.getTestMethod().ifPresent(method -> this.name = method.getName());

`

61

61

`try {

`

62

62

`FileUtils.deleteDirectory(testDir);

`

63

63

` } catch (IOException e) {

`

`@@ -72,7 +72,7 @@ public void setUp() {

`

72

72

` * @throws java.net.URISyntaxException if any.

`

73

73

` */

`

74

74

`@Test

`

75

``

`-

public void testCrossPlatformIncludesString() throws IOException, URISyntaxException {

`

``

75

`+

void crossPlatformIncludesString() throws IOException, URISyntaxException {

`

76

76

`DirectoryScanner ds = new DirectoryScanner();

`

77

77

`ds.setBasedir(new File(getTestResourcesDir() + File.separator + "directory-scanner").getCanonicalFile());

`

78

78

``

`@@ -98,7 +98,7 @@ public void testCrossPlatformIncludesString() throws IOException, URISyntaxExcep

`

98

98

` * @throws java.net.URISyntaxException if any.

`

99

99

` */

`

100

100

`@Test

`

101

``

`-

public void testCrossPlatformExcludesString() throws IOException, URISyntaxException {

`

``

101

`+

void crossPlatformExcludesString() throws IOException, URISyntaxException {

`

102

102

`DirectoryScanner ds = new DirectoryScanner();

`

103

103

`ds.setBasedir(new File(getTestResourcesDir() + File.separator + "directory-scanner").getCanonicalFile());

`

104

104

`ds.setIncludes(new String[] {"**"});

`

`@@ -161,11 +161,10 @@ private boolean checkTestFilesSymlinks() {

`

161

161

` }

`

162

162

`return true;

`

163

163

` } 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());

`

169

168

`System.out.println("On some OS (like Windows 10), files are present only if the clone/checkout is done"

`

170

169

` + " in administrator mode, and correct (symlinks and not flat file/directory)"

`

171

170

` + " if symlinks option are used (for git: git clone -c core.symlinks=true [url])");

`

`@@ -179,18 +178,18 @@ private boolean checkTestFilesSymlinks() {

`

179

178

` * @throws java.io.IOException if any.

`

180

179

` */

`

181

180

`@Test

`

182

``

`-

public void testGeneral() throws IOException {

`

``

181

`+

void general() throws IOException {

`

183

182

`this.createTestFiles();

`

184

183

``

185

184

`String includes = "scanner1.dat,scanner2.dat,scanner3.dat,scanner4.dat,scanner5.dat";

`

186

185

`String excludes = "scanner1.dat,scanner2.dat";

`

187

186

``

188

187

`List fileNames = FileUtils.getFiles(new File(testDir), includes, excludes, false);

`

189

188

``

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.");

`

194

193

` }

`

195

194

``

196

195

`/**

`

`@@ -199,7 +198,7 @@ public void testGeneral() throws IOException {

`

199

198

` * @throws java.io.IOException if any.

`

200

199

` */

`

201

200

`@Test

`

202

``

`-

public void testIncludesExcludesWithWhiteSpaces() throws IOException {

`

``

201

`+

void includesExcludesWithWhiteSpaces() throws IOException {

`

203

202

`this.createTestFiles();

`

204

203

``

205

204

`String includes = "scanner1.dat,\n \n,scanner2.dat \n\r, scanner3.dat\n, \tscanner4.dat,scanner5.dat\n,";

`

`@@ -208,17 +207,17 @@ public void testIncludesExcludesWithWhiteSpaces() throws IOException {

`

208

207

``

209

208

`List fileNames = FileUtils.getFiles(new File(testDir), includes, excludes, false);

`

210

209

``

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.");

`

215

214

` }

`

216

215

``

217

216

`/**

`

218

217

` *

testFollowSymlinksFalse.

`

219

218

` */

`

220

219

`@Test

`

221

``

`-

public void testFollowSymlinksFalse() {

`

``

220

`+

void followSymlinksFalse() {

`

222

221

`assumeTrue(checkTestFilesSymlinks());

`

223

222

``

224

223

`DirectoryScanner ds = new DirectoryScanner();

`

`@@ -253,7 +252,7 @@ private void assertAlwaysIncluded(List included) {

`

253

252

` *

testFollowSymlinks.

`

254

253

` */

`

255

254

`@Test

`

256

``

`-

public void testFollowSymlinks() {

`

``

255

`+

void followSymlinks() {

`

257

256

`assumeTrue(checkTestFilesSymlinks());

`

258

257

``

259

258

`DirectoryScanner ds = new DirectoryScanner();

`

`@@ -300,7 +299,7 @@ private void createTestDirectories() throws IOException {

`

300

299

` * @throws java.io.IOException if any.

`

301

300

` */

`

302

301

`@Test

`

303

``

`-

public void testDirectoriesWithHyphens() throws IOException {

`

``

302

`+

void directoriesWithHyphens() throws IOException {

`

304

303

`this.createTestDirectories();

`

305

304

``

306

305

`DirectoryScanner ds = new DirectoryScanner();

`

`@@ -313,7 +312,7 @@ public void testDirectoriesWithHyphens() throws IOException {

`

313

312

`ds.scan();

`

314

313

``

315

314

`String[] files = ds.getIncludedFiles();

`

316

``

`-

assertEquals("Wrong number of results.", 3, files.length);

`

``

315

`+

assertEquals(3, files.length, "Wrong number of results.");

`

317

316

` }

`

318

317

``

319

318

`/**

`

`@@ -322,7 +321,7 @@ public void testDirectoriesWithHyphens() throws IOException {

`

322

321

` * @throws java.io.IOException if any.

`

323

322

` */

`

324

323

`@Test

`

325

``

`-

public void testAntExcludesOverrideIncludes() throws IOException {

`

``

324

`+

void antExcludesOverrideIncludes() throws IOException {

`

326

325

`printTestHeader();

`

327

326

``

328

327

`File dir = new File(testDir, "regex-dir");

`

`@@ -360,7 +359,7 @@ public void testAntExcludesOverrideIncludes() throws IOException {

`

360

359

` * @throws java.io.IOException if any.

`

361

360

` */

`

362

361

`@Test

`

363

``

`-

public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException {

`

``

362

`+

void antExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException {

`

364

363

`printTestHeader();

`

365

364

``

366

365

`File dir = new File(testDir, "regex-dir");

`

`@@ -399,7 +398,7 @@ public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() throws IOExce

`

399

398

` * @throws java.io.IOException if any.

`

400

399

` */

`

401

400

`@Test

`

402

``

`-

public void testRegexIncludeWithExcludedPrefixDirs() throws IOException {

`

``

401

`+

void regexIncludeWithExcludedPrefixDirs() throws IOException {

`

403

402

`printTestHeader();

`

404

403

``

405

404

`File dir = new File(testDir, "regex-dir");

`

`@@ -433,7 +432,7 @@ public void testRegexIncludeWithExcludedPrefixDirs() throws IOException {

`

433

432

` * @throws java.io.IOException if any.

`

434

433

` */

`

435

434

`@Test

`

436

``

`-

public void testRegexExcludeWithNegativeLookahead() throws IOException {

`

``

435

`+

void regexExcludeWithNegativeLookahead() throws IOException {

`

437

436

`printTestHeader();

`

438

437

``

439

438

`File dir = new File(testDir, "regex-dir");

`

`@@ -472,7 +471,7 @@ public void testRegexExcludeWithNegativeLookahead() throws IOException {

`

472

471

` * @throws java.io.IOException if any.

`

473

472

` */

`

474

473

`@Test

`

475

``

`-

public void testRegexWithSlashInsideCharacterClass() throws IOException {

`

``

474

`+

void regexWithSlashInsideCharacterClass() throws IOException {

`

476

475

`printTestHeader();

`

477

476

``

478

477

`File dir = new File(testDir, "regex-dir");

`

`@@ -513,7 +512,7 @@ public void testRegexWithSlashInsideCharacterClass() throws IOException {

`

513

512

` * @throws java.io.IOException if occurs an I/O error.

`

514

513

` */

`

515

514

`@Test

`

516

``

`-

public void testDoNotScanUnnecesaryDirectories() throws IOException {

`

``

515

`+

void doNotScanUnnecesaryDirectories() throws IOException {

`

517

516

`createTestDirectories();

`

518

517

``

519

518

`// 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) {

`

582

581

` * @throws java.io.IOException if any.

`

583

582

` */

`

584

583

`@Test

`

585

``

`-

public void testIsSymbolicLink() throws IOException {

`

``

584

`+

void isSymbolicLink() throws IOException {

`

586

585

`assumeTrue(checkTestFilesSymlinks());

`

587

586

``

588

587

`final File directory = new File("src/test/resources/symlinks/src");

`

`@@ -599,7 +598,7 @@ public void testIsSymbolicLink() throws IOException {

`

599

598

` * @throws java.io.IOException if any.

`

600

599

` */

`

601

600

`@Test

`

602

``

`-

public void testIsParentSymbolicLink() throws IOException {

`

``

601

`+

void isParentSymbolicLink() throws IOException {

`

603

602

`assumeTrue(checkTestFilesSymlinks());

`

604

603

``

605

604

`final File directory = new File("src/test/resources/symlinks/src");

`