ShareUtilsTest.kt 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Nextcloud Talk application
  3. *
  4. * @author Mario Danic
  5. * Copyright (C) 2017-2019 Mario Danic <mario@lovelyhq.com>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU 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 General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. package com.nextcloud.talk.utils
  21. import android.content.Context
  22. import android.content.res.Resources
  23. import com.nextcloud.talk.R
  24. import com.nextcloud.talk.data.user.model.User
  25. import com.nextcloud.talk.models.domain.ConversationModel
  26. import com.nextcloud.talk.users.UserManager
  27. import io.reactivex.Maybe
  28. import org.junit.Assert
  29. import org.junit.Before
  30. import org.junit.Test
  31. import org.mockito.Mock
  32. import org.mockito.Mockito
  33. import org.mockito.MockitoAnnotations
  34. class ShareUtilsTest {
  35. @Mock
  36. private val context: Context? = null
  37. @Mock
  38. private val resources: Resources? = null
  39. @Mock
  40. private val userManager: UserManager? = null
  41. @Mock
  42. private val user: User? = null
  43. private val baseUrl = "https://my.nextcloud.com"
  44. private val token = "2aotbrjr"
  45. private lateinit var conversation: ConversationModel
  46. @Before
  47. fun setUp() {
  48. MockitoAnnotations.openMocks(this)
  49. Mockito.`when`(userManager!!.currentUser).thenReturn(Maybe.just(user))
  50. Mockito.`when`(user!!.baseUrl).thenReturn(baseUrl)
  51. Mockito.`when`(context!!.resources).thenReturn(resources)
  52. Mockito.`when`(resources!!.getString(R.string.nc_share_text))
  53. .thenReturn("Join the conversation at %1\$s/index.php/call/%2\$s")
  54. Mockito.`when`(resources.getString(R.string.nc_share_text_pass)).thenReturn("\nPassword: %1\$s")
  55. conversation = ConversationModel(token = token)
  56. }
  57. @Test
  58. fun stringForIntent_noPasswordGiven_correctStringWithoutPasswordReturned() {
  59. val expectedResult = String.format(
  60. "Join the conversation at %s/index.php/call/%s",
  61. baseUrl,
  62. token
  63. )
  64. Assert.assertEquals(
  65. "Intent string was not as expected",
  66. expectedResult,
  67. ShareUtils.getStringForIntent(context!!, userManager!!.currentUser.blockingGet(), conversation)
  68. )
  69. }
  70. }