Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/androidTest/java/com/owncloud/android/AbstractIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@
import org.junit.BeforeClass;
import org.junit.runner.RunWith;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import static junit.framework.TestCase.assertTrue;

/**
* Common base for all integration tests
*/

@RunWith(AndroidJUnit4.class)
public abstract class AbstractIT {
private static final int BUFFER_SIZE = 1024;

protected static OwnCloudClient client;
protected static Context context;

Expand All @@ -43,6 +51,43 @@ public static void beforeAll() {
client.setUserId(loginName); // for test same as userId
}

public String createFile(String name) throws IOException {
File tempDir = context.getFilesDir();

File file = new File(tempDir + File.separator + name);
file.createNewFile();

assertTrue(file.exists());

return file.getAbsolutePath();
}

/**
* Extracts file from AssetManager to cache folder.
*
* @param fileName Name of the asset file to extract.
* @param context Android context to access assets and file system.
* @return File instance of the extracted file.
*/
public static File extractAsset(String fileName, Context context) throws IOException {
File extractedFile = new File(context.getCacheDir() + File.separator + fileName);
if (!extractedFile.exists()) {
InputStream in = null;
FileOutputStream out = null;
in = context.getAssets().open(fileName);
out = new FileOutputStream(extractedFile);
byte[] buffer = new byte[BUFFER_SIZE];
int readCount;
while ((readCount = in.read(buffer)) != -1) {
out.write(buffer, 0, readCount);
}
out.flush();
out.close();
in.close();
}
return extractedFile;
}

@After
public void after() {
ArrayList list = new ReadFolderRemoteOperation("/").execute(client).getData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import androidx.test.ext.junit.runners.AndroidJUnit4;


/**
* Created by tobi on 3/21/18.
*/

@RunWith(AndroidJUnit4.class)
public class ExceptionParserIT {

@Test
Expand Down
4 changes: 0 additions & 4 deletions src/androidTest/java/com/owncloud/android/FileIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@
import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation;

import org.junit.Test;
import org.junit.runner.RunWith;

import androidx.test.ext.junit.runners.AndroidJUnit4;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
* Tests related to file operations
*/
@RunWith(AndroidJUnit4.class)
public class FileIT extends AbstractIT {
@Test
public void testCreateFolderSuccess() {
Expand Down
Loading