|
23 | 23 | import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; |
24 | 24 | import static java.util.concurrent.TimeUnit.SECONDS; |
25 | 25 | import static org.awaitility.Awaitility.await; |
| 26 | +import static org.hamcrest.Matchers.anyOf; |
26 | 27 | import static org.hamcrest.Matchers.is; |
27 | 28 | import static org.junit.Assert.assertFalse; |
28 | 29 | import static org.junit.Assert.assertTrue; |
@@ -234,18 +235,18 @@ public void testOverwriteExistingFile() throws Throwable { |
234 | 235 | final File file = File.createTempFile("test", "txt"); |
235 | 236 | final File to = dir.toPath().resolve("test.txt").toFile(); |
236 | 237 | Files.copy(file, to); |
237 | | - java.util.List<ChangeKind> changes = java.util.Collections.synchronizedList(new java.util.ArrayList<>()); |
| 238 | + AtomicReference<ChangeKind> change = new AtomicReference<>(); |
238 | 239 |
|
239 | | - try (DirectoryWatcher dw = new DirectoryWatcherBuilder().path(dir).quietPeriodInMS(0).listener((p, c) -> { |
| 240 | + try (DirectoryWatcher dw = new DirectoryWatcherBuilder().path(dir).listener((p, c) -> { |
240 | 241 | System.out.println("c = " + c); |
241 | | - changes.add(c); |
| 242 | + change.set(c); |
242 | 243 | }).exceptionHandler(assertableExceptionHandler).build()) { |
243 | 244 | // We want it to call the listener once for setup, even without any change |
244 | 245 | assertableExceptionHandler.assertNoErrorInTheBackgroundThread(); |
245 | 246 | java.nio.file.Files.move(file.toPath(), to.toPath(), REPLACE_EXISTING); |
246 | 247 |
|
247 | 248 | // Files.move(file, to); |
248 | | - await().atMost(5, SECONDS).until(() -> changes.contains(ChangeKind.CREATED) || changes.contains(ChangeKind.MODIFIED)); |
| 249 | + await().atMost(5, SECONDS).until(change::get, anyOf(is(ChangeKind.CREATED), is(ChangeKind.MODIFIED))); |
249 | 250 | } |
250 | 251 | } |
251 | 252 |
|
|
0 commit comments