Fix registration of second account on first run

Fixes #4234
Fixes #4529
Fixes #4462

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
This commit is contained in:
Chris Narkiewicz 2019-09-22 18:42:09 +01:00
parent 6f8c91e446
commit 953ee005e5
No known key found for this signature in database
GPG key ID: 30D28CA4CCC665C6
2 changed files with 75 additions and 2 deletions

View file

@ -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

View file

@ -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)
}
}