Skip to content

Commit 3652654

Browse files
Merge pull request #134 from nextcloud/photoSearchLimit
Photo search limit
2 parents 8f57cbd + 87642a0 commit 3652654

File tree

6 files changed

+670
-251
lines changed

6 files changed

+670
-251
lines changed

src/androidTest/java/com/owncloud/android/AbstractIT.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,24 @@
1818
import org.junit.BeforeClass;
1919
import org.junit.runner.RunWith;
2020

21+
import java.io.File;
22+
import java.io.FileOutputStream;
23+
import java.io.IOException;
24+
import java.io.InputStream;
2125
import java.util.ArrayList;
2226

27+
import static junit.framework.TestCase.assertTrue;
28+
2329
/**
2430
* Common base for all integration tests
2531
*/
2632

2733
@RunWith(AndroidJUnit4.class)
2834
public abstract class AbstractIT {
35+
private static final int BUFFER_SIZE = 1024;
36+
2937
protected static OwnCloudClient client;
30-
protected static Context context;
38+
private static Context context;
3139

3240
@BeforeClass
3341
public static void beforeAll() {
@@ -43,6 +51,54 @@ public static void beforeAll() {
4351
client.setUserId(loginName); // for test same as userId
4452
}
4553

54+
public String createFile(String name) throws IOException {
55+
File tempDir = context.getExternalCacheDir();
56+
57+
if (tempDir == null) {
58+
throw new IOException("Temp dir is null");
59+
}
60+
61+
if (!tempDir.exists()) {
62+
if (!tempDir.mkdirs()) {
63+
throw new IOException("Cannot create temp dir: " + tempDir.getAbsolutePath());
64+
}
65+
}
66+
67+
File file = new File(tempDir + File.separator + name);
68+
69+
if (!file.exists() && !file.createNewFile()) {
70+
throw new IOException("Cannot create file: " + file.getAbsolutePath());
71+
}
72+
73+
assertTrue(file.exists());
74+
75+
return file.getAbsolutePath();
76+
}
77+
78+
/**
79+
* Extracts file from AssetManager to cache folder.
80+
*
81+
* @param fileName Name of the asset file to extract.
82+
* @param context Android context to access assets and file system.
83+
* @return File instance of the extracted file.
84+
*/
85+
public static File extractAsset(String fileName, Context context) throws IOException {
86+
File extractedFile = new File(context.getCacheDir() + File.separator + fileName);
87+
if (!extractedFile.exists()) {
88+
InputStream in = context.getAssets().open(fileName);
89+
FileOutputStream out = new FileOutputStream(extractedFile);
90+
byte[] buffer = new byte[BUFFER_SIZE];
91+
int readCount;
92+
while ((readCount = in.read(buffer)) != -1) {
93+
out.write(buffer, 0, readCount);
94+
}
95+
out.flush();
96+
out.close();
97+
in.close();
98+
}
99+
return extractedFile;
100+
}
101+
46102
@After
47103
public void after() {
48104
ArrayList list = new ReadFolderRemoteOperation("/").execute(client).getData();

src/androidTest/java/com/owncloud/android/ExceptionParserIT.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@
44

55
import org.junit.Assert;
66
import org.junit.Test;
7-
import org.junit.runner.RunWith;
87

98
import java.io.ByteArrayInputStream;
109
import java.io.IOException;
1110
import java.io.InputStream;
1211

13-
import androidx.test.ext.junit.runners.AndroidJUnit4;
14-
1512

1613
/**
1714
* Created by tobi on 3/21/18.
1815
*/
1916

20-
@RunWith(AndroidJUnit4.class)
2117
public class ExceptionParserIT {
2218

2319
@Test

src/androidTest/java/com/owncloud/android/FileIT.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,13 @@
77
import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation;
88

99
import org.junit.Test;
10-
import org.junit.runner.RunWith;
11-
12-
import androidx.test.ext.junit.runners.AndroidJUnit4;
1310

1411
import static org.junit.Assert.assertFalse;
1512
import static org.junit.Assert.assertTrue;
1613

1714
/**
1815
* Tests related to file operations
1916
*/
20-
@RunWith(AndroidJUnit4.class)
2117
public class FileIT extends AbstractIT {
2218
@Test
2319
public void testCreateFolderSuccess() {

0 commit comments

Comments
 (0)