From 953ee005e5c6c39fb03241eb90bd94f2613e72d1 Mon Sep 17 00:00:00 2001 From: Chris Narkiewicz Date: Sun, 22 Sep 2019 18:42:09 +0100 Subject: [PATCH] Fix registration of second account on first run Fixes #4234 Fixes #4529 Fixes #4462 Signed-off-by: Chris Narkiewicz --- .../onboarding/OnboardingServiceImpl.kt | 7 +- .../onboarding/OnboardingServiceTest.kt | 70 +++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/test/java/com/nextcloud/client/onboarding/OnboardingServiceTest.kt diff --git a/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt b/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt index 157acb99c2..d352ec1551 100644 --- a/src/main/java/com/nextcloud/client/onboarding/OnboardingServiceImpl.kt +++ b/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 diff --git a/src/test/java/com/nextcloud/client/onboarding/OnboardingServiceTest.kt b/src/test/java/com/nextcloud/client/onboarding/OnboardingServiceTest.kt new file mode 100644 index 0000000000..fdcc0bdfe5 --- /dev/null +++ b/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 + * + * 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 . + */ +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) + } +}