FileUtilTest.kt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Andy Scherzinger
  5. * Copyright (C) 2020 Andy Scherzinger
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. package com.owncloud.android.utils
  21. import com.owncloud.android.AbstractIT
  22. import org.junit.Assert
  23. import org.junit.Test
  24. import java.io.File
  25. class FileUtilTest : AbstractIT() {
  26. @Test
  27. fun assertNullInput() {
  28. Assert.assertEquals("", FileUtil.getFilenameFromPathString(null))
  29. }
  30. @Test
  31. fun assertEmptyInput() {
  32. Assert.assertEquals("", FileUtil.getFilenameFromPathString(""))
  33. }
  34. @Test
  35. fun assertFileInput() {
  36. val file = getDummyFile("empty.txt")
  37. Assert.assertEquals("empty.txt", FileUtil.getFilenameFromPathString(file.absolutePath))
  38. }
  39. @Test
  40. fun assertSlashInput() {
  41. val tempPath =
  42. File(FileStorageUtils.getInternalTemporalPath(account.name, targetContext) + File.pathSeparator + "folder")
  43. if (!tempPath.exists()) {
  44. Assert.assertTrue(tempPath.mkdirs())
  45. }
  46. Assert.assertEquals("", FileUtil.getFilenameFromPathString(tempPath.absolutePath))
  47. }
  48. @Test
  49. fun assertDotFileInput() {
  50. val file = getDummyFile(".dotfile.ext")
  51. Assert.assertEquals(".dotfile.ext", FileUtil.getFilenameFromPathString(file.absolutePath))
  52. }
  53. @Test
  54. fun assertFolderInput() {
  55. val tempPath = File(FileStorageUtils.getInternalTemporalPath(account.name, targetContext))
  56. if (!tempPath.exists()) {
  57. Assert.assertTrue(tempPath.mkdirs())
  58. }
  59. Assert.assertEquals("", FileUtil.getFilenameFromPathString(tempPath.absolutePath))
  60. }
  61. @Test
  62. fun assertNoFileExtensionInput() {
  63. val file = getDummyFile("file")
  64. Assert.assertEquals("file", FileUtil.getFilenameFromPathString(file.absolutePath))
  65. }
  66. }