OnboardingServiceTest.kt 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Nextcloud Android client application
  2. *
  3. * @author Chris Narkiewicz
  4. * Copyright (C) 2019 Chris Narkiewicz <hello@ezaquarii.com>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.nextcloud.client.onboarding
  20. import android.accounts.Account
  21. import android.content.res.Resources
  22. import com.nextcloud.client.account.CurrentAccountProvider
  23. import com.nextcloud.client.preferences.AppPreferences
  24. import com.nhaarman.mockitokotlin2.whenever
  25. import org.junit.Assert.assertFalse
  26. import org.junit.Assert.assertTrue
  27. import org.junit.Before
  28. import org.junit.Test
  29. import org.mockito.Mock
  30. import org.mockito.MockitoAnnotations
  31. class OnboardingServiceTest {
  32. @Mock
  33. private lateinit var resources: Resources
  34. @Mock
  35. private lateinit var preferences: AppPreferences
  36. @Mock
  37. private lateinit var currentAccountProvider: CurrentAccountProvider
  38. @Mock
  39. private lateinit var account: Account
  40. private lateinit var onboardingService: OnboardingServiceImpl
  41. @Before
  42. fun setUp() {
  43. MockitoAnnotations.initMocks(this)
  44. onboardingService = OnboardingServiceImpl(resources, preferences, currentAccountProvider)
  45. }
  46. @Test
  47. fun `first run flag toggles with current current account`() {
  48. // GIVEN
  49. // current account is not set
  50. // first run flag is true
  51. assertTrue(onboardingService.isFirstRun)
  52. // WHEN
  53. // current account is set
  54. whenever(currentAccountProvider.currentAccount).thenReturn(account)
  55. // THEN
  56. // first run flag toggles
  57. assertFalse(onboardingService.isFirstRun)
  58. }
  59. }