ArbitraryDataProviderIT.kt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. *
  3. * Nextcloud Android client application
  4. *
  5. * @author Tobias Kaminsky
  6. * Copyright (C) 2020 Tobias Kaminsky
  7. * Copyright (C) 2020 Nextcloud GmbH
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. package com.owncloud.android.datamodel
  23. import com.owncloud.android.AbstractIT
  24. import org.junit.Assert.assertEquals
  25. import org.junit.Test
  26. class ArbitraryDataProviderIT : AbstractIT() {
  27. private val arbitraryDataProvider = ArbitraryDataProviderImpl(targetContext)
  28. @Test
  29. fun testNull() {
  30. val key = "DUMMY_KEY"
  31. arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, null)
  32. assertEquals("", arbitraryDataProvider.getValue(user.accountName, key))
  33. }
  34. @Test
  35. fun testString() {
  36. val key = "DUMMY_KEY"
  37. var value = "123"
  38. arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value)
  39. assertEquals(value, arbitraryDataProvider.getValue(user.accountName, key))
  40. value = ""
  41. arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value)
  42. assertEquals(value, arbitraryDataProvider.getValue(user.accountName, key))
  43. value = "-1"
  44. arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value)
  45. assertEquals(value, arbitraryDataProvider.getValue(user.accountName, key))
  46. }
  47. @Test
  48. fun testBoolean() {
  49. val key = "DUMMY_KEY"
  50. var value = true
  51. arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value)
  52. assertEquals(value, arbitraryDataProvider.getBooleanValue(user.accountName, key))
  53. value = false
  54. arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value)
  55. assertEquals(value, arbitraryDataProvider.getBooleanValue(user.accountName, key))
  56. }
  57. @Test
  58. fun testInteger() {
  59. val key = "DUMMY_KEY"
  60. var value = 1
  61. arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value.toString())
  62. assertEquals(value, arbitraryDataProvider.getIntegerValue(user.accountName, key))
  63. value = -1
  64. arbitraryDataProvider.storeOrUpdateKeyValue(user.accountName, key, value.toString())
  65. assertEquals(value, arbitraryDataProvider.getIntegerValue(user.accountName, key))
  66. }
  67. }