Skip to content

Commit

Permalink
Moved tests to the androidshared module
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Aug 21, 2024
1 parent f9377c4 commit e3f3d60
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object PathUtils {
"filePath: $filePath\n" +
"absoluteFilePath: $absoluteFilePath\n" +
"canonicalAbsoluteFilePath: $canonicalAbsoluteFilePath\n" +
"canonicalDirPath: $canonicalDirPath\n"
"canonicalDirPath: $canonicalDirPath"
)
}
return absoluteFilePath
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.odk.collect.androidshared.utils

import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.Test
import org.odk.collect.shared.TempFiles
import java.io.File

class PathUtilsTest {
@Test
fun `getAbsoluteFilePath() returns filePath prepended with dirPath`() {
val path = PathUtils.getAbsoluteFilePath("/anotherRoot/anotherDir", "root/dir/file")
assertThat(path, equalTo("/anotherRoot/anotherDir/root/dir/file"))
}

@Test
fun `getAbsoluteFilePath() returns valid path when filePath does not start with seperator`() {
val path = PathUtils.getAbsoluteFilePath("/root/dir", "file")
assertThat(path, equalTo("/root/dir/file"))
}

@Test
fun `getAbsoluteFilePath() returns filePath when it starts with dirPath`() {
val path = PathUtils.getAbsoluteFilePath("/root/dir", "/root/dir/file")
assertThat(path, equalTo("/root/dir/file"))
}

@Test
fun `getAbsoluteFilePath() works when dirPath is not canonical`() {
val tempDir = TempFiles.createTempDir()
val nonCanonicalPath =
tempDir.canonicalPath + File.separator + ".." + File.separator + tempDir.name
assertThat(File(nonCanonicalPath).canonicalPath, equalTo(tempDir.canonicalPath))

val path = PathUtils.getAbsoluteFilePath(nonCanonicalPath, "file")
assertThat(path, equalTo(nonCanonicalPath + File.separator + "file"))
}
}
36 changes: 0 additions & 36 deletions shared/src/test/java/org/odk/collect/shared/PathUtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,8 @@ package org.odk.collect.shared
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.Test
// import java.io.File

class PathUtilsTest {

// @Test
// fun `getAbsoluteFilePath() returns filePath prepended with dirPath`() {
// val path = PathUtils.getAbsoluteFilePath("/anotherRoot/anotherDir", "root/dir/file")
// assertThat(path, equalTo("/anotherRoot/anotherDir/root/dir/file"))
// }
//
// @Test
// fun `getAbsoluteFilePath() returns valid path when filePath does not start with seperator`() {
// val path = PathUtils.getAbsoluteFilePath("/root/dir", "file")
// assertThat(path, equalTo("/root/dir/file"))
// }
//
// @Test
// fun `getAbsoluteFilePath() returns filePath when it starts with dirPath`() {
// val path = PathUtils.getAbsoluteFilePath("/root/dir", "/root/dir/file")
// assertThat(path, equalTo("/root/dir/file"))
// }
//
// @Test(expected = SecurityException::class)
// fun `getAbsoluteFilePath() throws SecurityException when filePath is outside the dirPath`() {
// PathUtils.getAbsoluteFilePath("/root/dir", "../tmp/file")
// }
//
// @Test
// fun `getAbsoluteFilePath() works when dirPath is not canonical`() {
// val tempDir = TempFiles.createTempDir()
// val nonCanonicalPath =
// tempDir.canonicalPath + File.separator + ".." + File.separator + tempDir.name
// assertThat(File(nonCanonicalPath).canonicalPath, equalTo(tempDir.canonicalPath))
//
// val path = PathUtils.getAbsoluteFilePath(nonCanonicalPath, "file")
// assertThat(path, equalTo(nonCanonicalPath + File.separator + "file"))
// }

@Test
fun `getRelativeFilePath() returns filePath with dirPath removed`() {
val path = PathUtils.getRelativeFilePath("/root/dir", "/root/dir/file")
Expand Down

0 comments on commit e3f3d60

Please sign in to comment.