@@ -112,4 +112,62 @@ void watchSingleFile() throws IOException {
112112 await ("Single file change" ).untilTrue (changed );
113113 }
114114 }
115+
116+ @ Test
117+ void moveRegularFileBetweenNestedDirectories () throws IOException {
118+ var parent = testDir .getTestDirectory ();
119+ var child1 = Files .createDirectories (parent .resolve ("from" ));
120+ var child2 = Files .createDirectories (parent .resolve ("to" ));
121+ var file = Files .createFile (child1 .resolve ("file.txt" ));
122+
123+ var parentWatchBookkeeper = new TestHelper .Bookkeeper ();
124+ var parentWatchConfig = Watch
125+ .build (parent , WatchScope .PATH_AND_ALL_DESCENDANTS )
126+ .on (parentWatchBookkeeper );
127+
128+ var child1WatchBookkeeper = new TestHelper .Bookkeeper ();
129+ var child1WatchConfig = Watch
130+ .build (child1 , WatchScope .PATH_AND_CHILDREN )
131+ .on (child1WatchBookkeeper );
132+
133+ var child2WatchBookkeeper = new TestHelper .Bookkeeper ();
134+ var child2WatchConfig = Watch
135+ .build (child2 , WatchScope .PATH_AND_CHILDREN )
136+ .on (child2WatchBookkeeper );
137+
138+ var fileWatchBookkeeper = new TestHelper .Bookkeeper ();
139+ var fileWatchConfig = Watch
140+ .build (file , WatchScope .PATH_ONLY )
141+ .on (fileWatchBookkeeper );
142+
143+ try (var parentWatch = parentWatchConfig .start ();
144+ var child1Watch = child1WatchConfig .start ();
145+ var child2Watch = child2WatchConfig .start ();
146+ var fileWatch = fileWatchConfig .start ()) {
147+
148+ var source = child1 .resolve (file .getFileName ());
149+ var target = child2 .resolve (file .getFileName ());
150+ Files .move (source , target );
151+
152+ await ("Move should be observed as delete by `parent` watch (file tree)" )
153+ .until (() -> parentWatchBookkeeper
154+ .events ().kind (DELETED ).rootPath (parent ).relativePath (parent .relativize (source )).any ());
155+
156+ await ("Move should be observed as create by `parent` watch (file tree)" )
157+ .until (() -> parentWatchBookkeeper
158+ .events ().kind (CREATED ).rootPath (parent ).relativePath (parent .relativize (target )).any ());
159+
160+ await ("Move should be observed as delete by `child1` watch (single directory)" )
161+ .until (() -> child1WatchBookkeeper
162+ .events ().kind (DELETED ).rootPath (child1 ).relativePath (child1 .relativize (source )).any ());
163+
164+ await ("Move should be observed as create by `child2` watch (single directory)" )
165+ .until (() -> child2WatchBookkeeper
166+ .events ().kind (CREATED ).rootPath (child2 ).relativePath (child2 .relativize (target )).any ());
167+
168+ await ("Move should be observed as delete by `file` watch (regular file)" )
169+ .until (() -> fileWatchBookkeeper
170+ .events ().kind (DELETED ).rootPath (source ).any ());
171+ }
172+ }
115173}
0 commit comments