Migrate integration tests to NIO2 Path API#11364
Open
gnodet wants to merge 1 commit into
Open
Conversation
ee35106 to
b14e415
Compare
c68efc7 to
e16c71d
Compare
Migrate Maven Integration Tests from java.io.File to NIO2 java.nio.file.Path API, making Path-based methods the primary API while maintaining familiar method names. Infrastructure: - Verifier: Path-based overloads, NIO2 file operations, custom deleteDirectoryRecursively using Files.walk(), InvalidPathException fallback to File API for Windows trailing-space paths - AbstractMavenIntegrationTestCase: extractResources() returns Path, strips leading '/' for correct Path.resolve() behavior - ItUtils: centralized FileUtils wrappers (copyDirectoryStructure, deleteDirectory, createFile, lastModified) - HttpServer: source(Path) overload for file-based serving Test migration: - 735+ integration test files migrated to Path-based API - File -> Path, new File(dir, sub) -> dir.resolve(sub) - getAbsolutePath() -> toString(), FileReader -> Files.newBufferedReader - Files.deleteIfExists() where old File.delete() was lenient - Platform-specific fixes: Windows drive-relative paths (File.separator prefix for subpath), Unix Path.subpath() skip New tests: - VerifierNIO2Test, NIO2MigrationVerificationTest, AbstractMavenIntegrationTestCaseNIO2Test Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
b2766e8 to
6b47f1c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrate Maven Integration Tests from
java.io.Fileto NIO2java.nio.file.PathAPI, making Path-based methods the primary API while maintaining familiar method names.Changes Made
Infrastructure Migration
Migrated
Verifierclass to NIO2:loadProperties(),loadFile(),filterFile()FileUtilsoperations with native NIO2 methods (Files.walk(),Files.copy(), etc.)deleteDirectoryRecursively()usingFiles.walk()PathandDirectoryStreamorg.codehaus.plexus.util.FileUtilsInvalidPathExceptionfallback toFileAPI for paths NIO2 rejects (e.g., trailing spaces on Windows)Migrated
AbstractMavenIntegrationTestCaseclass:extractResources()to returnPathinstead ofFile/from resource paths —Path.resolve("/child")replaces the base entirely (unlikenew File(parent, "/child")which silently strips it)FileimportsCentralized
FileUtilsusage intoItUtils:copyDirectoryStructure(),deleteDirectory(),createFile(),lastModified(),canonicalPath()FileUtils.copyDirectoryStructure(preserves hierarchy),Files.createFile,Files.getLastModifiedTimewith existence check,Files.deleteIfExistsUpdated
HttpServerwithsource(Path)overload for file-based servingMade Path-based methods the primary API:
extractResources()now returnsPath(wasFile)filterFile()methods now returnPath(wereFile)Integration Tests Migration
extractResources()returningPathFiletoPathnew File(dir, subpath)patterns todir.resolve(subpath).getAbsolutePath()calls to.toString()for Path variablesFileReaderwithFiles.newBufferedReaderFiles.deleteIfExists()where oldFile.delete()was lenient about missing filesFile.separatorprefix afterPath.subpath()(strips root entirely unlikeFile)Path.subpath()creates plain relative paths resolved from CWD, not from filesystem rootTesting
VerifierNIO2Testfor new NIO2 functionalityNIO2MigrationVerificationTestto verify common integration test patternsAbstractMavenIntegrationTestCaseNIO2TestAPI Changes
Before (File-based)
After (Path-based)
Migration Statistics
Key NIO2 Behavioral Differences Addressed
java.io.Filejava.nio.file.Pathnew File(parent, "/child")strips leading/Path.resolve("/child")replaces base entirely/inextractResources()file.lastModified()returns0Lfor missing filesFiles.getLastModifiedTime()throwsNoSuchFileException0Lfile.delete()returnsfalsefor missing filesFiles.delete()throwsNoSuchFileExceptionFiles.deleteIfExists()new File(path)accepts any stringPaths.get(path)validates (rejects trailing spaces on Windows)InvalidPathException, fall back toFileAPIPath.subpath()strips root entirelyFile.separatoron Windows