Repository navigation
Conversation
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
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.
testFailedFileDeletionThrowsExceptiontests inAbstractFileItemWriterTestsandStaxEventItemWriterTestsfail on Windows.The tests stubbed
File.delete()on a spy usingwhen(...), which invoked the real method during stubbing. On Unix-like systems, this deleted the open output file, causing the subsequentFiles.delete()call inclose()to throwNoSuchFileException, which made the tests pass by accident. On Windows, the file could not be deleted while the writer kept it open, soFiles.delete()inclose()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 theclose()call with try-with-resources.Supersedes #5465