@@ -268,6 +268,12 @@ private static class RemoveIndexChangeListener implements IndexChangedListener {
268
268
final Queue <String > filesToAdd = new ConcurrentLinkedQueue <>();
269
269
final Queue <String > removedFiles = new ConcurrentLinkedQueue <>();
270
270
271
+ private final String path ;
272
+
273
+ RemoveIndexChangeListener (String path ) {
274
+ this .path = path ;
275
+ }
276
+
271
277
@ Override
272
278
public void fileAdd (String path , String analyzer ) {
273
279
filesToAdd .add (path );
@@ -290,11 +296,12 @@ public void fileRemoved(String path) {
290
296
// The test for the file existence needs to be performed here
291
297
// since the call to {@code removeFile()} will be eventually
292
298
// followed by {@code addFile()} that will create the file again.
293
- if (path .equals ("/mercurial/bar.txt" )) {
299
+ if (path .equals (this . path )) {
294
300
RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
295
301
File f = new File (env .getDataRootPath (),
296
302
TandemPath .join ("historycache" + path , ".gz" ));
297
- Assert .assertTrue ("history cache file should be preserved" , f .exists ());
303
+ Assert .assertTrue (String .format ("history cache file %s should be preserved" , f ),
304
+ f .exists ());
298
305
}
299
306
removedFiles .add (path );
300
307
}
@@ -326,22 +333,20 @@ public void testRemoveFileOnFileChange() throws Exception {
326
333
Project project = new Project ("mercurial" , "/mercurial" );
327
334
IndexDatabase idb = new IndexDatabase (project );
328
335
assertNotNull (idb );
329
- RemoveIndexChangeListener listener = new RemoveIndexChangeListener ();
336
+ RemoveIndexChangeListener listener = new RemoveIndexChangeListener ("/mercurial/bar.txt" );
330
337
idb .addIndexChangedListener (listener );
331
338
idb .update ();
332
339
Assert .assertEquals (5 , listener .filesToAdd .size ());
333
340
listener .reset ();
334
341
335
342
// Change a file so that it gets picked up by the indexer.
336
- Thread .sleep (1100 );
343
+ // Thread.sleep(1100);
337
344
File bar = new File (testrepo .getSourceRoot () + File .separator + "mercurial" ,
338
345
"bar.txt" );
339
346
Assert .assertTrue (bar .exists ());
340
- FileWriter fw = new FileWriter (bar , true );
341
- BufferedWriter bw = new BufferedWriter (fw );
342
- bw .write ("foo\n " );
343
- bw .close ();
344
- fw .close ();
347
+ try (BufferedWriter bw = new BufferedWriter (new FileWriter (bar , true ))) {
348
+ bw .write ("foo\n " );
349
+ }
345
350
346
351
// reindex
347
352
idb .update ();
0 commit comments