Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java

Issue 29347192: Issue 4181 - Fix FilterEngineTest tests (Closed)
Patch Set: marked method as static Created Dec. 2, 2016, 6:14 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..130759b7cc299e1739a3c03a9d94c460172f93a3 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,56 @@
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 File buildTmpFileSystemPath() throws IOException
+ {
+ File tmpFileSystemPath = FileSystemUtils
+ .generateUniqueFile(null, ".fs", getContext().getCacheDir());
+ tmpFileSystemPath.mkdirs();
+ return tmpFileSystemPath;
+ }
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
+ @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();
+ }
}

Powered by Google App Engine
This is Rietveld