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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations