Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/ImportantFileWriterAndroidTest.java

Issue 2708243004: Auto convert content shell tests to JUnit4 (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/android/javatests/src/org/chromium/content/browser/ImportantFileWriterAndroidTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ImportantFileWriterAndroidTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ImportantFileWriterAndroidTest.java
index 5efe0c7e75625ecb86c313b59af95d7596fc0405..2398c37e42ce39052dfd916b219540b06f057802 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/ImportantFileWriterAndroidTest.java
+++ b/content/public/android/javatests/src/org/chromium/content/browser/ImportantFileWriterAndroidTest.java
@@ -4,11 +4,19 @@
package org.chromium.content.browser;
+import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import org.chromium.base.ImportantFileWriterAndroid;
+import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.Feature;
-import org.chromium.content.browser.test.NativeLibraryTestBase;
+import org.chromium.content.browser.test.NativeLibraryTestRule;
import java.io.DataInputStream;
import java.io.File;
@@ -23,62 +31,62 @@ import java.io.IOException;
* work, so is not attempting to test that writes are atomic. Instead it is just
* testing that the Java code is calling the native code correctly.
*/
-public class ImportantFileWriterAndroidTest extends NativeLibraryTestBase {
+@RunWith(BaseJUnit4ClassRunner.class)
+public class ImportantFileWriterAndroidTest {
+ @Rule
+ public NativeLibraryTestRule mActivityTestRule = new NativeLibraryTestRule();
private void checkFile(File testFile, byte[] data) {
- assertTrue(testFile.exists());
+ Assert.assertTrue(testFile.exists());
try {
byte[] fileData = new byte[(int) testFile.length()];
DataInputStream dis =
new DataInputStream(new FileInputStream(testFile));
dis.readFully(fileData);
dis.close();
- assertEquals("Data length wrong", data.length, fileData.length);
+ Assert.assertEquals("Data length wrong", data.length, fileData.length);
for (int i = 0; i < data.length; i++) {
- assertEquals("Data byte wrong", data[i], fileData[i]);
+ Assert.assertEquals("Data byte wrong", data[i], fileData[i]);
}
} catch (IOException e) {
- fail("Failed to read file");
+ Assert.fail("Failed to read file");
}
}
+ @Test
@SmallTest
@Feature({"Android-AppBase"})
public void testAtomicWrite() {
// Try writing a file that can't be created.
byte[] data1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
- assertFalse("Writing bad file succeded",
- ImportantFileWriterAndroid.writeFileAtomically(
- "/junk/junk", data1));
- File dir = getInstrumentation().getTargetContext().getFilesDir();
+ Assert.assertFalse("Writing bad file succeded",
+ ImportantFileWriterAndroid.writeFileAtomically("/junk/junk", data1));
+ File dir = InstrumentationRegistry.getInstrumentation().getTargetContext().getFilesDir();
File testFile = new File(dir, "ImportantFileTest");
// Make sure the file doesn't already exist
if (testFile.exists()) {
- assertTrue(testFile.delete());
+ Assert.assertTrue(testFile.delete());
}
// Write a new file
- assertTrue("Writing new file failed",
- ImportantFileWriterAndroid.writeFileAtomically(
- testFile.getAbsolutePath(), data1));
+ Assert.assertTrue("Writing new file failed",
+ ImportantFileWriterAndroid.writeFileAtomically(testFile.getAbsolutePath(), data1));
checkFile(testFile, data1);
byte[] data2 = {10, 20, 30, 40, 50, 60, 70, 80};
// Overwrite an existing file
- assertTrue("Writing exiting file failed",
- ImportantFileWriterAndroid.writeFileAtomically(
- testFile.getAbsolutePath(), data2));
+ Assert.assertTrue("Writing exiting file failed",
+ ImportantFileWriterAndroid.writeFileAtomically(testFile.getAbsolutePath(), data2));
checkFile(testFile, data2);
// Done, tidy up
- assertTrue(testFile.delete());
+ Assert.assertTrue(testFile.delete());
}
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
- loadNativeLibraryNoBrowserProcess();
+ mActivityTestRule.loadNativeLibraryNoBrowserProcess();
}
}

Powered by Google App Engine
This is Rietveld 408576698