mirror of
https://github.com/nextcloud/android.git
synced 2024-11-24 06:05:42 +03:00
Merge pull request #13248 from nextcloud/bugfix/set-default-account
Bug-Fix Set Default Account Instead Using Lateinit Variable
This commit is contained in:
commit
c6c96ca25a
3 changed files with 56 additions and 53 deletions
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
package com.owncloud.android.utils
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.rules.ActivityScenarioRule
|
||||
import com.nextcloud.client.account.UserAccountManager
|
||||
import com.nextcloud.client.account.UserAccountManagerImpl
|
||||
import com.nextcloud.client.mixins.SessionMixin
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
class SessionMixinTest : AbstractIT() {
|
||||
|
||||
private lateinit var userAccountManager: UserAccountManager
|
||||
private lateinit var session: SessionMixin
|
||||
|
||||
private var scenario: ActivityScenario<FileDisplayActivity>? = null
|
||||
val intent = Intent(ApplicationProvider.getApplicationContext(), FileDisplayActivity::class.java)
|
||||
|
||||
@get:Rule
|
||||
val activityRule = ActivityScenarioRule<FileDisplayActivity>(intent)
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
userAccountManager = UserAccountManagerImpl.fromContext(targetContext)
|
||||
|
||||
scenario = activityRule.scenario
|
||||
scenario?.onActivity { sut ->
|
||||
session = SessionMixin(
|
||||
sut,
|
||||
userAccountManager
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun startAccountCreation() {
|
||||
session.startAccountCreation()
|
||||
|
||||
scenario = activityRule.scenario
|
||||
scenario?.onActivity { sut ->
|
||||
assert(sut.account.name == userAccountManager.accounts.first().name)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,7 +29,7 @@ class SessionMixin(
|
|||
private val activity: Activity,
|
||||
private val accountManager: UserAccountManager
|
||||
) : ActivityMixin {
|
||||
lateinit var currentAccount: Account
|
||||
var currentAccount: Account = getDefaultAccount()
|
||||
private set
|
||||
|
||||
val capabilities: OCCapability?
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2020 Chris Narkiewicz <hello@ezaquarii.com>
|
||||
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
|
||||
*/
|
||||
package com.nextcloud.client.mixins
|
||||
|
||||
import android.app.Activity
|
||||
import com.nextcloud.client.account.UserAccountManager
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.same
|
||||
import org.mockito.Mockito.spy
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.mockito.kotlin.verify
|
||||
|
||||
class SessionMixinTest {
|
||||
|
||||
@Mock
|
||||
private lateinit var activity: Activity
|
||||
|
||||
@Mock
|
||||
private lateinit var userAccountManager: UserAccountManager
|
||||
|
||||
private lateinit var session: SessionMixin
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
session = spy(
|
||||
SessionMixin(
|
||||
activity,
|
||||
userAccountManager
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `start account creation`() {
|
||||
// WHEN
|
||||
// start account creation flow
|
||||
session.startAccountCreation()
|
||||
|
||||
// THEN
|
||||
// start is delegated to account manager
|
||||
// account manager receives parent activity
|
||||
verify(userAccountManager).startAccountCreation(same(activity))
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue