Skip to content

Commit

Permalink
Improved AppStateProviderTest
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 authored and seadowg committed May 5, 2021
1 parent 2549d44 commit b550a29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions collect_app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ dependencies {
testImplementation "junit:junit:4.13.2"
testImplementation "org.mockito:mockito-core:3.7.7"
testImplementation 'org.mockito:mockito-inline:3.7.7'
testImplementation "org.mockito.kotlin:mockito-kotlin:3.2.0"

testImplementation(project(path: ':testshared')) {
exclude group: 'org.robolectric' // Some tests in `collect_app` don't work with newer Robolectric
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.odk.collect.android.utilities

import android.content.pm.PackageInfo
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito.`when`
import org.mockito.Mockito.mock
import org.mockito.kotlin.whenever
import org.odk.collect.android.preferences.keys.MetaKeys
import org.odk.collect.shared.Settings

Expand All @@ -26,25 +26,25 @@ class AppStateProviderTest {
fun `When app is newly installed isFreshInstall() should return true when opened for the first time`() {
packageInfo.firstInstallTime = 100
packageInfo.lastUpdateTime = 100
`when`(metaSettings.contains(MetaKeys.FIRST_LAUNCH)).thenReturn(false)
whenever(metaSettings.contains(MetaKeys.FIRST_LAUNCH)).thenReturn(false)

assertThat(appStateProvider.isFreshInstall(), `is`(true))
assertThat(appStateProvider.isFreshInstall(), equalTo(true))
}

@Test
fun `When app is newly installed isFreshInstall() should return false when opened not for the first time`() {
packageInfo.firstInstallTime = 100
packageInfo.lastUpdateTime = 100
`when`(metaSettings.contains(MetaKeys.FIRST_LAUNCH)).thenReturn(true)
whenever(metaSettings.contains(MetaKeys.FIRST_LAUNCH)).thenReturn(true)

assertThat(appStateProvider.isFreshInstall(), `is`(false))
assertThat(appStateProvider.isFreshInstall(), equalTo(false))
}

@Test
fun `When app is updated should return false`() {
packageInfo.firstInstallTime = 100
packageInfo.lastUpdateTime = 200

assertThat(appStateProvider.isFreshInstall(), `is`(false))
assertThat(appStateProvider.isFreshInstall(), equalTo(false))
}
}

0 comments on commit b550a29

Please sign in to comment.