Skip to content

Commit e02cf5b

Browse files
committed
fix tests
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 841200e commit e02cf5b

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

app/src/test/java/com/owncloud/android/datamodel/MoveFilesHierarchyTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ class MoveFilesHierarchyTest : MoveFilesTestBase() {
5656
fileId = 1
5757
mimeType = MimeType.DIRECTORY
5858
}
59+
60+
try {
61+
for (entity in entities) {
62+
// entity.path may be nullable; treat as empty string if so
63+
val path = entity.path.orEmpty()
64+
val relative = path.removePrefix("/")
65+
val local = File(tempDir, relative)
66+
if (path.endsWith("/")) {
67+
local.mkdirs()
68+
} else {
69+
local.parentFile?.mkdirs()
70+
if (!local.exists()) local.createNewFile()
71+
}
72+
}
73+
} catch (_: Exception) {
74+
}
75+
5976
manager.moveLocalFile(folder, targetFolderPath, targetParentPath)
6077
}
6178

app/src/test/java/com/owncloud/android/datamodel/MoveFilesTestBase.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ import io.mockk.unmockkAll
2929
import org.junit.After
3030
import org.junit.Before
3131

32-
@Suppress("LongParameterList","TooManyFunctions", "DEPRECATION")
32+
@Suppress("LongParameterList", "TooManyFunctions", "DEPRECATION")
3333
abstract class MoveFilesTestBase {
3434

3535
companion object {
3636
const val ACCOUNT_NAME = "user@nextcloud.example.com"
37-
const val SAVE_PATH = "/storage/emulated/0/nextcloud/$ACCOUNT_NAME"
37+
val SAVE_PATH: String = (System.getProperty("java.io.tmpdir") ?: "") + "/nextcloud/" + ACCOUNT_NAME
3838
const val OLD_PATH = "/documents/report.pdf"
3939
const val TARGET_PATH = "/archive/report.pdf"
4040
const val TARGET_PARENT_PATH = "/archive/"
@@ -71,6 +71,15 @@ abstract class MoveFilesTestBase {
7171
SAVE_PATH + secondArg<OCFile>().remotePath
7272
}
7373

74+
try {
75+
val localOldFile = java.io.File(SAVE_PATH + OLD_PATH)
76+
localOldFile.parentFile?.mkdirs()
77+
if (!localOldFile.exists()) {
78+
localOldFile.createNewFile()
79+
}
80+
} catch (_: Exception) {
81+
}
82+
7483
mockkStatic(TextUtils::class)
7584
every { TextUtils.isEmpty(any()) } answers { arg<CharSequence?>(0).isNullOrEmpty() }
7685

@@ -86,6 +95,11 @@ abstract class MoveFilesTestBase {
8695
@After
8796
fun tearDownBase() {
8897
unmockkAll()
98+
try {
99+
val tmp = java.io.File(SAVE_PATH)
100+
if (tmp.exists()) tmp.deleteRecursively()
101+
} catch (_: Exception) {
102+
}
89103
}
90104

91105
fun stubTargetParent(path: String = TARGET_PARENT_PATH, id: Long = 99L): OCFile {

0 commit comments

Comments
 (0)