From e839759bd47fa6ddce89efc04169c15f8094b398 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 8 Jul 2024 13:37:18 +0200 Subject: [PATCH 1/3] Fix Signed-off-by: alperozturk --- app/src/main/java/com/nextcloud/client/mixins/SessionMixin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/nextcloud/client/mixins/SessionMixin.kt b/app/src/main/java/com/nextcloud/client/mixins/SessionMixin.kt index 6cbd513263..21e69dc2a8 100644 --- a/app/src/main/java/com/nextcloud/client/mixins/SessionMixin.kt +++ b/app/src/main/java/com/nextcloud/client/mixins/SessionMixin.kt @@ -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? From d982ae2e7a3ccb523eecbfd0d7c4bf7e67958033 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 8 Jul 2024 15:05:55 +0200 Subject: [PATCH 2/3] Fix test Signed-off-by: alperozturk --- .../android/utils/SessionMixinTest.kt | 55 +++++++++++++++++++ .../client/mixins/SessionMixinTest.kt | 52 ------------------ 2 files changed, 55 insertions(+), 52 deletions(-) create mode 100644 app/src/androidTest/java/com/owncloud/android/utils/SessionMixinTest.kt delete mode 100644 app/src/test/java/com/nextcloud/client/mixins/SessionMixinTest.kt diff --git a/app/src/androidTest/java/com/owncloud/android/utils/SessionMixinTest.kt b/app/src/androidTest/java/com/owncloud/android/utils/SessionMixinTest.kt new file mode 100644 index 0000000000..5a833c9afb --- /dev/null +++ b/app/src/androidTest/java/com/owncloud/android/utils/SessionMixinTest.kt @@ -0,0 +1,55 @@ +/* + * Nextcloud - Android Client + * + * SPDX-FileCopyrightText: 2024 Alper Ozturk + * 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? = null + val intent = Intent(ApplicationProvider.getApplicationContext(), FileDisplayActivity::class.java) + + @get:Rule + val activityRule = ActivityScenarioRule(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) + } + } +} diff --git a/app/src/test/java/com/nextcloud/client/mixins/SessionMixinTest.kt b/app/src/test/java/com/nextcloud/client/mixins/SessionMixinTest.kt deleted file mode 100644 index 135eeb07c3..0000000000 --- a/app/src/test/java/com/nextcloud/client/mixins/SessionMixinTest.kt +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Nextcloud - Android Client - * - * SPDX-FileCopyrightText: 2020 Chris Narkiewicz - * 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)) - } -} From f27fb2186e015edb91f4ceabba5b2a299b5daa3d Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 8 Jul 2024 15:06:29 +0200 Subject: [PATCH 3/3] Fix code analytics Signed-off-by: alperozturk --- .../java/com/owncloud/android/utils/SessionMixinTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/androidTest/java/com/owncloud/android/utils/SessionMixinTest.kt b/app/src/androidTest/java/com/owncloud/android/utils/SessionMixinTest.kt index 5a833c9afb..11914ed394 100644 --- a/app/src/androidTest/java/com/owncloud/android/utils/SessionMixinTest.kt +++ b/app/src/androidTest/java/com/owncloud/android/utils/SessionMixinTest.kt @@ -19,7 +19,7 @@ import org.junit.Before import org.junit.Rule import org.junit.Test -class SessionMixinTest: AbstractIT() { +class SessionMixinTest : AbstractIT() { private lateinit var userAccountManager: UserAccountManager private lateinit var session: SessionMixin