Fixed bug in FolderObserver, improved tests (ref #337).

This commit is contained in:
Felix Ableitner 2015-04-09 01:23:30 +02:00
parent 8c75a8913d
commit 1bc4935463
2 changed files with 33 additions and 10 deletions

View File

@ -2,7 +2,6 @@ package com.nutomic.syncthingandroid.test.util;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
import com.nutomic.syncthingandroid.syncthing.RestApi;
import com.nutomic.syncthingandroid.test.MockContext;
@ -55,40 +54,63 @@ public class FolderObserverTest extends AndroidTestCase
mCurrentTest = "testRecursion";
File subFolder = new File(mTestFolder, "subfolder");
subFolder.mkdir();
FolderObserver ro = new FolderObserver(this, createFolder(mCurrentTest));
FolderObserver fo = new FolderObserver(this, createFolder(mCurrentTest));
File testFile = new File(subFolder, "test");
mLatch = new CountDownLatch(1);
testFile.createNewFile();
mLatch.await(1, TimeUnit.SECONDS);
ro.stopWatching();
fo.stopWatching();
}
@MediumTest
public void testRemoveDirectory() throws IOException {
mCurrentTest = "testRemoveDirectory";
public void testRemoveFile() throws IOException, InterruptedException {
mCurrentTest = "testRemoveFile";
File test = new File(mTestFolder, "test");
test.createNewFile();
FolderObserver fo = new FolderObserver(this, createFolder(mCurrentTest));
mLatch = new CountDownLatch(1);
test.delete();
mLatch.await(1, TimeUnit.SECONDS);
assertEquals(0, mLatch.getCount());
fo.stopWatching();
}
@MediumTest
public void testMoveDirectoryOut() throws IOException, InterruptedException {
mCurrentTest = "testMoveDirectory";
File subFolder = new File(mTestFolder, "subfolder");
subFolder.mkdir();
FolderObserver ro = new FolderObserver(this, createFolder(mCurrentTest));
FolderObserver fo = new FolderObserver(this, createFolder(mCurrentTest));
File movedSubFolder = new File(getContext().getFilesDir(), subFolder.getName());
subFolder.renameTo(movedSubFolder);
File testFile = new File(movedSubFolder, "should-not-notifiy");
mLatch = new CountDownLatch(1);
testFile.createNewFile();
ro.stopWatching();
Util.deleteRecursive(subFolder);
mLatch.await(1, TimeUnit.SECONDS);
assertEquals(1, mLatch.getCount());
fo.stopWatching();
}
@MediumTest
public void testAddDirectory() throws IOException, InterruptedException {
mCurrentTest = "testAddDirectory";
File subFolder = new File(mTestFolder, "subfolder");
FolderObserver ro = new FolderObserver(this, createFolder(mCurrentTest));
subFolder.mkdir();
File testFile = new File(subFolder, "test");
FolderObserver fo = new FolderObserver(this, createFolder(mCurrentTest));
mLatch = new CountDownLatch(1);
testFile.createNewFile();
mLatch.await(1, TimeUnit.SECONDS);
ro.stopWatching();
assertEquals(0, mLatch.getCount());
fo.stopWatching();
}
}

View File

@ -107,6 +107,7 @@ public class FolderObserver extends FileObserver {
break;
}
}
mListener.onFolderFileChange(mFolder.ID, fullPath.getPath());
break;
case MOVED_TO:
// fall through