Search in sources :

Example 6 with EditableFileAbstraction

use of com.amaze.filemanager.filesystem.EditableFileAbstraction in project AmazeFileManager by TeamAmaze.

the class WriteFileAbstractionTest method testWriteContentUri.

@Test
public void testWriteContentUri() {
    Uri uri = Uri.parse("content://com.amaze.filemanager.test/foobar.txt");
    Context ctx = ApplicationProvider.getApplicationContext();
    ContentResolver cr = ctx.getContentResolver();
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    shadowOf(cr).registerOutputStream(uri, bout);
    WriteFileAbstraction task = new WriteFileAbstraction(ctx, cr, new EditableFileAbstraction(ctx, uri), contents, null, false, null);
    int result = task.doInBackground();
    assertEquals(NORMAL, result);
    assertEquals(contents, new String(bout.toByteArray(), StandardCharsets.UTF_8));
}
Also used : Context(android.content.Context) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) EditableFileAbstraction(com.amaze.filemanager.filesystem.EditableFileAbstraction) Test(org.junit.Test)

Example 7 with EditableFileAbstraction

use of com.amaze.filemanager.filesystem.EditableFileAbstraction in project AmazeFileManager by TeamAmaze.

the class WriteFileAbstractionTest method testWriteFileRootCacheFileNotFound.

@Test
@Config(shadows = { BlockAllOutputStreamsFileUtil.class })
public void testWriteFileRootCacheFileNotFound() {
    File file = new File(Environment.getExternalStorageDirectory(), "test.txt");
    Uri uri = Uri.fromFile(file);
    File cacheFile = new File(Environment.getExternalStorageDirectory(), "test.txt.cache");
    Context ctx = ApplicationProvider.getApplicationContext();
    ContentResolver cr = ctx.getContentResolver();
    WriteFileAbstraction task = new WriteFileAbstraction(ctx, cr, new EditableFileAbstraction(ctx, uri), contents, cacheFile, true, null);
    int result = task.doInBackground();
    assertEquals(EXCEPTION_STREAM_NOT_FOUND, result);
}
Also used : Context(android.content.Context) File(java.io.File) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) EditableFileAbstraction(com.amaze.filemanager.filesystem.EditableFileAbstraction) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 8 with EditableFileAbstraction

use of com.amaze.filemanager.filesystem.EditableFileAbstraction in project AmazeFileManager by TeamAmaze.

the class WriteFileAbstractionTest method testWriteFileRoot.

@Test
@Config(shadows = { BlockAllOutputStreamsFileUtil.class, BypassMountPartitionRootUtils.class })
public void testWriteFileRoot() throws IOException {
    File file = new File(Environment.getExternalStorageDirectory(), "test.txt");
    File cacheFile = File.createTempFile("test.txt", "cache");
    cacheFile.deleteOnExit();
    Uri uri = Uri.fromFile(file);
    Context ctx = ApplicationProvider.getApplicationContext();
    ContentResolver cr = ctx.getContentResolver();
    WriteFileAbstraction task = new WriteFileAbstraction(ctx, cr, new EditableFileAbstraction(ctx, uri), contents, cacheFile, true, null);
    int result = task.doInBackground();
    assertEquals(NORMAL, result);
    String verify = IoUtils.readFully(new FileInputStream(file));
    assertEquals(contents, verify);
}
Also used : Context(android.content.Context) File(java.io.File) Uri(android.net.Uri) FileInputStream(java.io.FileInputStream) ContentResolver(android.content.ContentResolver) EditableFileAbstraction(com.amaze.filemanager.filesystem.EditableFileAbstraction) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 9 with EditableFileAbstraction

use of com.amaze.filemanager.filesystem.EditableFileAbstraction in project AmazeFileManager by TeamAmaze.

the class WriteFileAbstractionTest method testWriteFileRootNoCacheFile.

@Test
@Config(shadows = { BlockAllOutputStreamsFileUtil.class })
public void testWriteFileRootNoCacheFile() {
    File file = new File(Environment.getExternalStorageDirectory(), "test.txt");
    Uri uri = Uri.fromFile(file);
    Context ctx = ApplicationProvider.getApplicationContext();
    ContentResolver cr = ctx.getContentResolver();
    WriteFileAbstraction task = new WriteFileAbstraction(ctx, cr, new EditableFileAbstraction(ctx, uri), contents, null, true, null);
    int result = task.doInBackground();
    assertEquals(EXCEPTION_STREAM_NOT_FOUND, result);
}
Also used : Context(android.content.Context) File(java.io.File) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) EditableFileAbstraction(com.amaze.filemanager.filesystem.EditableFileAbstraction) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 10 with EditableFileAbstraction

use of com.amaze.filemanager.filesystem.EditableFileAbstraction in project AmazeFileManager by TeamAmaze.

the class WriteFileAbstractionTest method testWriteFileNonRoot.

@Test
public void testWriteFileNonRoot() throws IOException {
    File file = new File(Environment.getExternalStorageDirectory(), "test.txt");
    Uri uri = Uri.fromFile(file);
    Context ctx = ApplicationProvider.getApplicationContext();
    ContentResolver cr = ctx.getContentResolver();
    WriteFileAbstraction task = new WriteFileAbstraction(ctx, cr, new EditableFileAbstraction(ctx, uri), contents, null, false, null);
    int result = task.doInBackground();
    assertEquals(NORMAL, result);
    String verify = IoUtils.readFully(new FileInputStream(file));
    assertEquals(contents, verify);
}
Also used : Context(android.content.Context) File(java.io.File) Uri(android.net.Uri) FileInputStream(java.io.FileInputStream) ContentResolver(android.content.ContentResolver) EditableFileAbstraction(com.amaze.filemanager.filesystem.EditableFileAbstraction) Test(org.junit.Test)

Aggregations

Uri (android.net.Uri)10 EditableFileAbstraction (com.amaze.filemanager.filesystem.EditableFileAbstraction)10 ContentResolver (android.content.ContentResolver)8 Context (android.content.Context)8 Test (org.junit.Test)8 File (java.io.File)6 Config (org.robolectric.annotation.Config)4 FileInputStream (java.io.FileInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ActivityManager (android.app.ActivityManager)1 Window (android.view.Window)1 FrameLayout (android.widget.FrameLayout)1 SystemBarTintManager (com.readystatesoftware.systembartint.SystemBarTintManager)1 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1 StringReader (java.io.StringReader)1