FileUtilTest.kt 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 = File(FileStorageUtils.getTemporalPath(account.name) + File.pathSeparator + "folder")
  42. if (!tempPath.exists()) {
  43. Assert.assertTrue(tempPath.mkdirs())
  44. }
  45. Assert.assertEquals("", FileUtil.getFilenameFromPathString(tempPath.absolutePath))
  46. }
  47. @Test
  48. fun assertDotFileInput() {
  49. val file = getDummyFile(".dotfile.ext")
  50. Assert.assertEquals(".dotfile.ext", FileUtil.getFilenameFromPathString(file.absolutePath))
  51. }
  52. @Test
  53. fun assertFolderInput() {
  54. val tempPath = File(FileStorageUtils.getTemporalPath(account.name))
  55. if (!tempPath.exists()) {
  56. Assert.assertTrue(tempPath.mkdirs())
  57. }
  58. Assert.assertEquals("", FileUtil.getFilenameFromPathString(tempPath.absolutePath))
  59. }
  60. @Test
  61. fun assertNoFileExtensionInput() {
  62. val file = getDummyFile("file")
  63. Assert.assertEquals("file", FileUtil.getFilenameFromPathString(file.absolutePath))
  64. }
  65. }