@@ -114,8 +114,7 @@ public void testDirectory() {
114114 File testDirBFile1 = touch (new File (testDirB , "B-file1.java" ));
115115
116116 checkAndNotify ();
117- checkDirectoryCounts ("B" , 3 , 0 , 0 );
118- checkFileCounts ("B" , 4 , 0 , 0 );
117+ checkCollectionSizes ("B" , 3 , 0 , 0 , 4 , 0 , 0 );
119118 assertTrue ("B testDirA" , listener .getCreatedDirectories ().contains (testDirA ));
120119 assertTrue ("B testDirB" , listener .getCreatedDirectories ().contains (testDirB ));
121120 assertTrue ("B testDirC" , listener .getCreatedDirectories ().contains (testDirC ));
@@ -131,16 +130,14 @@ public void testDirectory() {
131130 testDirAFile4 = touch (testDirAFile4 );
132131 FileUtils .deleteDirectory (testDirB );
133132 checkAndNotify ();
134- checkDirectoryCounts ("D" , 0 , 0 , 1 );
135- checkFileCounts ("D" , 0 , 1 , 1 );
133+ checkCollectionSizes ("D" , 0 , 0 , 1 , 0 , 1 , 1 );
136134 assertTrue ("D testDirB" , listener .getDeletedDirectories ().contains (testDirB ));
137135 assertTrue ("D testDirAFile4" , listener .getChangedFiles ().contains (testDirAFile4 ));
138136 assertTrue ("D testDirBFile1" , listener .getDeletedFiles ().contains (testDirBFile1 ));
139137
140138 FileUtils .deleteDirectory (testDir );
141139 checkAndNotify ();
142- checkDirectoryCounts ("E" , 0 , 0 , 2 );
143- checkFileCounts ("E" , 0 , 0 , 3 );
140+ checkCollectionSizes ("E" , 0 , 0 , 2 , 0 , 0 , 3 );
144141 assertTrue ("E testDirA" , listener .getDeletedDirectories ().contains (testDirA ));
145142 assertTrue ("E testDirAFile1" , listener .getDeletedFiles ().contains (testDirAFile1 ));
146143 assertFalse ("E testDirAFile2" , listener .getDeletedFiles ().contains (testDirAFile2 ));
@@ -177,8 +174,7 @@ public void testFileCreate() {
177174 File testDirAFile5 = new File (testDirA , "A-file5.java" );
178175
179176 checkAndNotify ();
180- checkDirectoryCounts ("B" , 1 , 0 , 0 );
181- checkFileCounts ("B" , 2 , 0 , 0 );
177+ checkCollectionSizes ("B" , 1 , 0 , 0 , 2 , 0 , 0 );
182178 assertFalse ("B testDirAFile1" , listener .getCreatedFiles ().contains (testDirAFile1 ));
183179 assertTrue ("B testDirAFile2" , listener .getCreatedFiles ().contains (testDirAFile2 ));
184180 assertFalse ("B testDirAFile3" , listener .getCreatedFiles ().contains (testDirAFile3 ));
@@ -196,22 +192,25 @@ public void testFileCreate() {
196192
197193 // Create file with name < first entry
198194 testDirAFile1 = touch (testDirAFile1 );
195+ testDirA = touch (testDirA );
199196 checkAndNotify ();
200- checkFileCounts ("D" , 1 , 0 , 0 );
197+ checkCollectionSizes ("D" , 0 , 1 , 0 , 1 , 0 , 0 );
201198 assertTrue ("D testDirAFile1 exists" , testDirAFile1 .exists ());
202199 assertTrue ("D testDirAFile1" , listener .getCreatedFiles ().contains (testDirAFile1 ));
203200
204201 // Create file with name between 2 entries
205202 testDirAFile3 = touch (testDirAFile3 );
203+ testDirA = touch (testDirA );
206204 checkAndNotify ();
207- checkFileCounts ("E" , 1 , 0 , 0 );
205+ checkCollectionSizes ("E" , 0 , 1 , 0 , 1 , 0 , 0 );
208206 assertTrue ("E testDirAFile3 exists" , testDirAFile3 .exists ());
209207 assertTrue ("E testDirAFile3" , listener .getCreatedFiles ().contains (testDirAFile3 ));
210208
211209 // Create file with name > last entry
212210 testDirAFile5 = touch (testDirAFile5 );
211+ testDirA = touch (testDirA );
213212 checkAndNotify ();
214- checkFileCounts ("F" , 1 , 0 , 0 );
213+ checkCollectionSizes ("F" , 0 , 1 , 0 , 1 , 0 , 0 );
215214 assertTrue ("F testDirAFile5 exists" , testDirAFile5 .exists ());
216215 assertTrue ("F testDirAFile5" , listener .getCreatedFiles ().contains (testDirAFile5 ));
217216 } catch (Exception e ) {
@@ -237,8 +236,7 @@ public void testFileUpdate() {
237236 File testDirAFile5 = touch (new File (testDirA , "A-file5.java" ));
238237
239238 checkAndNotify ();
240- checkDirectoryCounts ("B" , 1 , 0 , 0 );
241- checkFileCounts ("B" , 5 , 0 , 0 );
239+ checkCollectionSizes ("B" , 1 , 0 , 0 , 5 , 0 , 0 );
242240 assertTrue ("B testDirAFile1" , listener .getCreatedFiles ().contains (testDirAFile1 ));
243241 assertTrue ("B testDirAFile2" , listener .getCreatedFiles ().contains (testDirAFile2 ));
244242 assertTrue ("B testDirAFile3" , listener .getCreatedFiles ().contains (testDirAFile3 ));
@@ -256,20 +254,23 @@ public void testFileUpdate() {
256254
257255 // Update first entry
258256 testDirAFile1 = touch (testDirAFile1 );
257+ testDirA = touch (testDirA );
259258 checkAndNotify ();
260- checkFileCounts ("D" , 0 , 1 , 0 );
259+ checkCollectionSizes ("D" , 0 , 1 , 0 , 0 , 1 , 0 );
261260 assertTrue ("D testDirAFile1" , listener .getChangedFiles ().contains (testDirAFile1 ));
262261
263262 // Update file with name between 2 entries
264263 testDirAFile3 = touch (testDirAFile3 );
264+ testDirA = touch (testDirA );
265265 checkAndNotify ();
266- checkFileCounts ("E" , 0 , 1 , 0 );
266+ checkCollectionSizes ("E" , 0 , 1 , 0 , 0 , 1 , 0 );
267267 assertTrue ("E testDirAFile3" , listener .getChangedFiles ().contains (testDirAFile3 ));
268268
269269 // Update last entry
270270 testDirAFile5 = touch (testDirAFile5 );
271+ testDirA = touch (testDirA );
271272 checkAndNotify ();
272- checkFileCounts ("F" , 0 , 1 , 0 );
273+ checkCollectionSizes ("F" , 0 , 1 , 0 , 0 , 1 , 0 );
273274 assertTrue ("F testDirAFile5" , listener .getChangedFiles ().contains (testDirAFile5 ));
274275 } catch (Exception e ) {
275276 fail ("Threw " + e );
@@ -300,8 +301,7 @@ public void testFileDelete() {
300301 assertTrue ("B testDirAFile5 exists" , testDirAFile5 .exists ());
301302
302303 checkAndNotify ();
303- checkDirectoryCounts ("B" , 1 , 0 , 0 );
304- checkFileCounts ("B" , 5 , 0 , 0 );
304+ checkCollectionSizes ("B" , 1 , 0 , 0 , 5 , 0 , 0 );
305305 assertTrue ("B testDirAFile1" , listener .getCreatedFiles ().contains (testDirAFile1 ));
306306 assertTrue ("B testDirAFile2" , listener .getCreatedFiles ().contains (testDirAFile2 ));
307307 assertTrue ("B testDirAFile3" , listener .getCreatedFiles ().contains (testDirAFile3 ));
@@ -313,22 +313,25 @@ public void testFileDelete() {
313313
314314 // Delete first entry
315315 FileUtils .deleteQuietly (testDirAFile1 );
316+ testDirA = touch (testDirA );
316317 checkAndNotify ();
317- checkFileCounts ("D" , 0 , 0 , 1 );
318+ checkCollectionSizes ("D" , 0 , 1 , 0 , 0 , 0 , 1 );
318319 assertFalse ("D testDirAFile1 exists" , testDirAFile1 .exists ());
319320 assertTrue ("D testDirAFile1" , listener .getDeletedFiles ().contains (testDirAFile1 ));
320321
321322 // Delete file with name between 2 entries
322323 FileUtils .deleteQuietly (testDirAFile3 );
324+ testDirA = touch (testDirA );
323325 checkAndNotify ();
324- checkFileCounts ("E" , 0 , 0 , 1 );
326+ checkCollectionSizes ("E" , 0 , 1 , 0 , 0 , 0 , 1 );
325327 assertFalse ("E testDirAFile3 exists" , testDirAFile3 .exists ());
326328 assertTrue ("E testDirAFile3" , listener .getDeletedFiles ().contains (testDirAFile3 ));
327329
328330 // Delete last entry
329331 FileUtils .deleteQuietly (testDirAFile5 );
332+ testDirA = touch (testDirA );
330333 checkAndNotify ();
331- checkFileCounts ("F" , 0 , 0 , 1 );
334+ checkCollectionSizes ("F" , 0 , 1 , 0 , 0 , 0 , 1 );
332335 assertFalse ("F testDirAFile5 exists" , testDirAFile5 .exists ());
333336 assertTrue ("F testDirAFile5" , listener .getDeletedFiles ().contains (testDirAFile5 ));
334337
@@ -360,8 +363,7 @@ public void testObserveSingleFile() {
360363 assertTrue ("B testDirAFile2 exists" , testDirAFile2 .exists ());
361364 assertTrue ("B testDirAFile3 exists" , testDirAFile3 .exists ());
362365 checkAndNotify ();
363- checkDirectoryCounts ("C" , 0 , 0 , 0 );
364- checkFileCounts ("C" , 1 , 0 , 0 );
366+ checkCollectionSizes ("C" , 0 , 0 , 0 , 1 , 0 , 0 );
365367 assertTrue ("C created" , listener .getCreatedFiles ().contains (testDirAFile1 ));
366368 assertFalse ("C created" , listener .getCreatedFiles ().contains (testDirAFile2 ));
367369 assertFalse ("C created" , listener .getCreatedFiles ().contains (testDirAFile3 ));
@@ -371,8 +373,7 @@ public void testObserveSingleFile() {
371373 testDirAFile2 = touch (testDirAFile2 );
372374 testDirAFile3 = touch (testDirAFile3 );
373375 checkAndNotify ();
374- checkDirectoryCounts ("D" , 0 , 0 , 0 );
375- checkFileCounts ("D" , 0 , 1 , 0 );
376+ checkCollectionSizes ("D" , 0 , 0 , 0 , 0 , 1 , 0 );
376377 assertTrue ("D changed" , listener .getChangedFiles ().contains (testDirAFile1 ));
377378 assertFalse ("D changed" , listener .getChangedFiles ().contains (testDirAFile2 ));
378379 assertFalse ("D changed" , listener .getChangedFiles ().contains (testDirAFile3 ));
@@ -385,8 +386,7 @@ public void testObserveSingleFile() {
385386 assertFalse ("E testDirAFile2 exists" , testDirAFile2 .exists ());
386387 assertFalse ("E testDirAFile3 exists" , testDirAFile3 .exists ());
387388 checkAndNotify ();
388- checkDirectoryCounts ("E" , 0 , 0 , 0 );
389- checkFileCounts ("E" , 0 , 0 , 1 );
389+ checkCollectionSizes ("E" , 0 , 0 , 0 , 0 , 0 , 1 );
390390 assertTrue ("E deleted" , listener .getDeletedFiles ().contains (testDirAFile1 ));
391391 assertFalse ("E deleted" , listener .getDeletedFiles ().contains (testDirAFile2 ));
392392 assertFalse ("E deleted" , listener .getDeletedFiles ().contains (testDirAFile3 ));
@@ -409,29 +409,22 @@ protected void checkAndNotify() throws Exception {
409409 * Check all the Collections are empty
410410 */
411411 private void checkCollectionsEmpty (String label ) {
412- checkDirectoryCounts ("EMPTY-" + label , 0 , 0 , 0 );
413- checkFileCounts ("EMPTY-" + label , 0 , 0 , 0 );
412+ checkCollectionSizes ("EMPTY-" + label , 0 , 0 , 0 , 0 , 0 , 0 );
414413 }
415414
416415 /**
417- * Check all the Directory Collections have the expected sizes.
416+ * Check all the Collections have the expected sizes.
418417 */
419- private void checkDirectoryCounts (String label , int dirCreate , int dirChange , int dirDelete ) {
418+ private void checkCollectionSizes (String label , int dirCreate , int dirChange , int dirDelete , int fileCreate , int fileChange , int fileDelete ) {
420419 label = label + "[" + listener .getCreatedDirectories ().size () +
421420 " " + listener .getChangedDirectories ().size () +
422- " " + listener .getDeletedDirectories ().size () + "]" ;
421+ " " + listener .getDeletedDirectories ().size () +
422+ " " + listener .getCreatedFiles ().size () +
423+ " " + listener .getChangedFiles ().size () +
424+ " " + listener .getDeletedFiles ().size () + "]" ;
423425 assertEquals (label + ": No. of directories created" , dirCreate , listener .getCreatedDirectories ().size ());
424426 assertEquals (label + ": No. of directories changed" , dirChange , listener .getChangedDirectories ().size ());
425427 assertEquals (label + ": No. of directories deleted" , dirDelete , listener .getDeletedDirectories ().size ());
426- }
427-
428- /**
429- * Check all the File Collections have the expected sizes.
430- */
431- private void checkFileCounts (String label , int fileCreate , int fileChange , int fileDelete ) {
432- label = label + "[" + listener .getCreatedFiles ().size () +
433- " " + listener .getChangedFiles ().size () +
434- " " + listener .getDeletedFiles ().size () + "]" ;
435428 assertEquals (label + ": No. of files created" , fileCreate , listener .getCreatedFiles ().size ());
436429 assertEquals (label + ": No. of files changed" , fileChange , listener .getChangedFiles ().size ());
437430 assertEquals (label + ": No. of files deleted" , fileDelete , listener .getDeletedFiles ().size ());
0 commit comments