Index: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java |
diff --git a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java |
index 85e983996ce91431cebf2ce8ab78270c298c485a..4b26b442d4f36b6144fd16564adf8cb9def566c3 100644 |
--- a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java |
+++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java |
@@ -18,24 +18,57 @@ |
package org.adblockplus.libadblockplus.tests; |
import org.adblockplus.libadblockplus.AppInfo; |
+import org.adblockplus.libadblockplus.FileSystemUtils; |
import org.adblockplus.libadblockplus.JsEngine; |
-import org.adblockplus.libadblockplus.LazyLogSystem; |
import org.adblockplus.libadblockplus.ThrowingWebRequest; |
import android.test.AndroidTestCase; |
+import java.io.File; |
+import java.io.IOException; |
+ |
public abstract class BaseJsTest extends AndroidTestCase |
{ |
- protected JsEngine jsEngine; |
+ protected JsEngine jsEngine; |
+ protected File tmpFileSystemPath; |
+ protected FileSystemUtils fileSystemUtils = new FileSystemUtils(); |
- @Override |
- protected void setUp() throws Exception |
- { |
- super.setUp(); |
+ protected File buildTmpFileSystemPath() throws IOException |
+ { |
+ File tmpFileSystemPath = fileSystemUtils |
+ .generateUniqueFileName(null, ".fs", getContext().getCacheDir()); |
+ tmpFileSystemPath.mkdirs(); |
+ return tmpFileSystemPath; |
+ } |
+ |
+ @Override |
+ protected void setUp() throws Exception |
+ { |
+ super.setUp(); |
+ |
+ jsEngine = new JsEngine(AppInfo.builder().build()); |
+ jsEngine.setDefaultLogSystem(); |
- jsEngine = new JsEngine(AppInfo.builder().build()); |
- jsEngine.setDefaultLogSystem(); |
- jsEngine.setDefaultFileSystem(getContext().getFilesDir().getAbsolutePath()); |
- jsEngine.setWebRequest(new ThrowingWebRequest()); |
+ // we need to generate new file system path in order |
+ // not to have JsEngine state from the previous test |
+ tmpFileSystemPath = buildTmpFileSystemPath(); |
+ jsEngine.setDefaultFileSystem(tmpFileSystemPath.getAbsolutePath()); |
+ jsEngine.setWebRequest(new ThrowingWebRequest()); |
+ } |
+ |
+ protected void cleanupFileSystem() |
+ { |
+ if (tmpFileSystemPath != null && tmpFileSystemPath.exists()) |
+ { |
+ fileSystemUtils.delete(tmpFileSystemPath, true); |
+ tmpFileSystemPath = null; |
} |
+ } |
+ |
+ @Override |
+ protected void tearDown() throws Exception |
+ { |
+ cleanupFileSystem(); |
+ super.tearDown(); |
+ } |
} |