-
-
Notifications
You must be signed in to change notification settings - Fork 6
test case that shows the issue #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -20,8 +20,10 @@ | |||||
| package ch.vorburger.fswatch.test; | ||||||
|
|
||||||
| import static com.google.common.base.Charsets.US_ASCII; | ||||||
| import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; | ||||||
| import static java.util.concurrent.TimeUnit.SECONDS; | ||||||
| import static org.awaitility.Awaitility.await; | ||||||
| import static org.hamcrest.Matchers.anyOf; | ||||||
| import static org.hamcrest.Matchers.is; | ||||||
| import static org.junit.Assert.assertFalse; | ||||||
| import static org.junit.Assert.assertTrue; | ||||||
|
|
@@ -35,6 +37,7 @@ | |||||
| import com.google.common.io.MoreFiles; | ||||||
| import java.io.File; | ||||||
| import java.nio.file.FileSystems; | ||||||
| import java.util.concurrent.atomic.AtomicReference; | ||||||
|
|
||||||
| import org.jspecify.annotations.Nullable; | ||||||
| import org.junit.BeforeClass; | ||||||
|
|
@@ -224,6 +227,29 @@ public void testDirectoryWatcherListenerExceptionPropagation() throws Throwable | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| public void testOverwriteExistingFile() throws Throwable { | ||||||
| var assertableExceptionHandler = new AssertableExceptionHandler(); | ||||||
| final File dir = new File("target/tests/DirectoryWatcherTest/overwrite_existing"); | ||||||
| dir.mkdirs(); | ||||||
| final File file = File.createTempFile("test", "txt"); | ||||||
| final File to = dir.toPath().resolve("test.txt").toFile(); | ||||||
| Files.copy(file, to); | ||||||
|
||||||
| Files.copy(file, to); | |
| java.nio.file.Files.copy(file.toPath(), to.toPath(), REPLACE_EXISTING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot
AI
Jan 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug output should be removed or replaced with proper logging. The test already has proper assertion mechanisms, and printing to System.out is not appropriate for production test code.
| System.out.println("c = " + c); |
Copilot
AI
Jan 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is misleading. The DirectoryWatcherBuilder does not call the listener during setup by default. The existingFiles flag is not set to true in this test, so the listener will only be called when file system events occur. This comment should be corrected or removed.
| // We want it to call the listener once for setup, even without any change | |
| // Verify that overwriting an existing file triggers a CREATED event via the listener |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot
AI
Jan 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented-out code should be removed. If this was an alternative implementation being considered, it should either be implemented properly or removed entirely.
| // Files.move(file, to); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
com.google.common.io.Files.copy(File, File)method is deprecated and scheduled for removal. It's better to use the standardjava.nio.file.Files.copy()instead. This also improves consistency with other parts of the new test that usejava.nio.file.Files.