PassCodeManagerTest.kt 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Álvaro Brey
  5. * Copyright (C) 2023 Álvaro Brey
  6. * Copyright (C) 2023 Nextcloud GmbH
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. package com.owncloud.android.authentication
  23. import com.nextcloud.client.core.Clock
  24. import com.nextcloud.client.preferences.AppPreferences
  25. import com.owncloud.android.ui.activity.SettingsActivity
  26. import io.mockk.MockKAnnotations
  27. import io.mockk.every
  28. import io.mockk.impl.annotations.MockK
  29. import org.junit.Assert.assertFalse
  30. import org.junit.Assert.assertTrue
  31. import org.junit.Before
  32. import org.junit.Test
  33. class PassCodeManagerTest {
  34. @MockK
  35. lateinit var appPreferences: AppPreferences
  36. @MockK
  37. lateinit var clockImpl: Clock
  38. lateinit var sut: PassCodeManager
  39. @Before
  40. fun before() {
  41. MockKAnnotations.init(this, relaxed = true)
  42. sut = PassCodeManager(appPreferences, clockImpl)
  43. }
  44. @Test
  45. fun testLocked() {
  46. every { appPreferences.lockPreference } returns SettingsActivity.LOCK_PASSCODE
  47. every { clockImpl.millisSinceBoot } returns 10000
  48. assertTrue("Passcode not requested", sut.passCodeShouldBeRequested(200))
  49. }
  50. @Test
  51. fun testPasscodeNotRequested_notEnabled() {
  52. every { appPreferences.lockPreference } returns ""
  53. every { clockImpl.millisSinceBoot } returns 10000
  54. assertFalse("Passcode requested but it shouldn't have been", sut.passCodeShouldBeRequested(200))
  55. }
  56. @Test
  57. fun testPasscodeNotRequested_unlockedRecently() {
  58. every { appPreferences.lockPreference } returns SettingsActivity.LOCK_PASSCODE
  59. every { clockImpl.millisSinceBoot } returns 210
  60. assertFalse("Passcode requested but it shouldn't have been", sut.passCodeShouldBeRequested(200))
  61. }
  62. }