Browse Source

Merge pull request #4538 from nextcloud/ezaquarii/fix-broken-account-registration

Fix registration of second account on first run
Tobias Kaminsky 5 years ago
parent
commit
5bcab439b4

+ 5 - 2
src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt

@@ -33,7 +33,7 @@ import com.owncloud.android.ui.activity.PassCodeActivity
 internal class OnboardingServiceImpl constructor(
     private val resources: Resources,
     private val preferences: AppPreferences,
-    accountProvider: CurrentAccountProvider
+    private val accountProvider: CurrentAccountProvider
 ) : OnboardingService {
 
     private companion object {
@@ -52,7 +52,10 @@ internal class OnboardingServiceImpl constructor(
             emptyArray()
         }
 
-    override val isFirstRun: Boolean = accountProvider.currentAccount == null
+    override val isFirstRun: Boolean
+        get() {
+            return accountProvider.currentAccount == null
+        }
 
     override fun shouldShowWhatsNew(callingContext: Context): Boolean {
         return callingContext !is PassCodeActivity && whatsNew.size > 0

+ 70 - 0
src/test/java/com/nextcloud/client/onboarding/OnboardingServiceTest.kt

@@ -0,0 +1,70 @@
+/* Nextcloud Android client application
+ *
+ * @author Chris Narkiewicz
+ * Copyright (C) 2019 Chris Narkiewicz <hello@ezaquarii.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.nextcloud.client.onboarding
+
+import android.accounts.Account
+import android.content.res.Resources
+import com.nextcloud.client.account.CurrentAccountProvider
+import com.nextcloud.client.preferences.AppPreferences
+import com.nhaarman.mockitokotlin2.whenever
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
+import org.junit.Before
+import org.junit.Test
+import org.mockito.Mock
+import org.mockito.MockitoAnnotations
+
+class OnboardingServiceTest {
+
+    @Mock
+    private lateinit var resources: Resources
+
+    @Mock
+    private lateinit var preferences: AppPreferences
+
+    @Mock
+    private lateinit var currentAccountProvider: CurrentAccountProvider
+
+    @Mock
+    private lateinit var account: Account
+
+    private lateinit var onboardingService: OnboardingServiceImpl
+
+    @Before
+    fun setUp() {
+        MockitoAnnotations.initMocks(this)
+        onboardingService = OnboardingServiceImpl(resources, preferences, currentAccountProvider)
+    }
+
+    @Test
+    fun `first run flag toggles with current current account`() {
+        // GIVEN
+        //      current account is not set
+        //      first run flag is true
+        assertTrue(onboardingService.isFirstRun)
+
+        // WHEN
+        //      current account is set
+        whenever(currentAccountProvider.currentAccount).thenReturn(account)
+
+        // THEN
+        //      first run flag toggles
+        assertFalse(onboardingService.isFirstRun)
+    }
+}