Skip to content

Fix file deletion failure tests - #5614

Open
noojung wants to merge 1 commit into
spring-projects:mainfrom
noojung:GH-5465
Open

noojung wants to merge 1 commit into
spring-projects:mainfrom
noojung:GH-5465

Conversation

@noojung

@noojung noojung commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

testFailedFileDeletionThrowsException tests in AbstractFileItemWriterTests and StaxEventItemWriterTests fail on Windows.

The tests stubbed File.delete() on a spy using when(...), which invoked the real method during stubbing. On Unix-like systems, this deleted the open output file, causing the subsequent Files.delete() call in close() to throw NoSuchFileException, which made the tests pass by accident. On Windows, the file could not be deleted while the writer kept it open, so Files.delete() in close() succeeded and the expected exception was not thrown.

Mock Files.delete() after opening the writer, so the deletion fails the same way on every platform. The static mocks are scoped to the close() call with try-with-resources.

Supersedes #5465

@noojung noojung changed the title Fix file deletion failure tests on Windows Fix file deletion failure tests Oct 19, 2026
The tests stubbed File.delete() on a spy using when(...), which invokes
the real method while stubbing. On Unix-like systems, this deleted the
open output file, so the subsequent Files.delete() call in close()
failed with a NoSuchFileException and the tests passed by accident.
On Windows, the open file could not be deleted at that point, so
Files.delete() succeeded in close() and no exception was thrown.

Since the writers delete the file with Files.delete(), mock that call
with Mockito.mockStatic(), scoped to the close() invocation only.

See spring-projects#5465

Co-authored-by: sumittlearnbay <sumit.learnbay@gmail.com>
Signed-off-by: Hyunwoo Jung <hyunwoojung@kakao.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant