fix(tests): return null/default values from faked android sdk

fixes behaviour of getFilesDir

Signed-off-by: SphericalKat <amolele@gmail.com>
This commit is contained in:
SphericalKat 2021-05-17 14:45:34 +05:30
parent bd09190786
commit 49d8183917
No known key found for this signature in database
GPG key ID: 02A1D73C0EE5E788
2 changed files with 10 additions and 6 deletions

View file

@ -47,6 +47,9 @@ android {
create("free") {} create("free") {}
create("nonFree") {} create("nonFree") {}
} }
testOptions {
unitTests.isReturnDefaultValues = true
}
} }
dependencies { dependencies {

View file

@ -9,6 +9,7 @@ package dev.msfjarvis.aps.util.settings
import android.content.Context import android.content.Context
import androidx.core.content.edit import androidx.core.content.edit
import com.github.ivanshafran.sharedpreferencesmock.SPMockBuilder
import dev.msfjarvis.aps.Application import dev.msfjarvis.aps.Application
import dev.msfjarvis.aps.util.extensions.getString import dev.msfjarvis.aps.util.extensions.getString
import dev.msfjarvis.aps.util.extensions.sharedPrefs import dev.msfjarvis.aps.util.extensions.sharedPrefs
@ -30,7 +31,7 @@ class MigrationsTest {
@Test @Test
fun verifySshWithCustomPortMigration() { fun verifySshWithCustomPortMigration() {
val context = Application.instance.applicationContext val context = SPMockBuilder().createContext()
context.sharedPrefs.edit { context.sharedPrefs.edit {
clear() clear()
putString(PreferenceKeys.GIT_REMOTE_PORT, "2200") putString(PreferenceKeys.GIT_REMOTE_PORT, "2200")
@ -50,7 +51,7 @@ class MigrationsTest {
@Test @Test
fun verifySshWithDefaultPortMigration() { fun verifySshWithDefaultPortMigration() {
val context = Application.instance.applicationContext val context = SPMockBuilder().createContext()
context.sharedPrefs.edit { context.sharedPrefs.edit {
clear() clear()
putString(PreferenceKeys.GIT_REMOTE_USERNAME, "msfjarvis") putString(PreferenceKeys.GIT_REMOTE_USERNAME, "msfjarvis")
@ -69,7 +70,7 @@ class MigrationsTest {
@Test @Test
fun verifyHttpsWithGitHubMigration() { fun verifyHttpsWithGitHubMigration() {
val context = Application.instance.applicationContext val context = SPMockBuilder().createContext()
context.sharedPrefs.edit { context.sharedPrefs.edit {
clear() clear()
putString(PreferenceKeys.GIT_REMOTE_USERNAME, "msfjarvis") putString(PreferenceKeys.GIT_REMOTE_USERNAME, "msfjarvis")
@ -88,7 +89,7 @@ class MigrationsTest {
@Test @Test
fun verifyHiddenFoldersMigrationIfDisabled() { fun verifyHiddenFoldersMigrationIfDisabled() {
val context = Application.instance.applicationContext val context = SPMockBuilder().createContext()
context.sharedPrefs.edit { clear() } context.sharedPrefs.edit { clear() }
runMigrations(context) runMigrations(context)
assertEquals(true, context.sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, true)) assertEquals(true, context.sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, true))
@ -97,7 +98,7 @@ class MigrationsTest {
@Test @Test
fun verifyHiddenFoldersMigrationIfEnabled() { fun verifyHiddenFoldersMigrationIfEnabled() {
val context = Application.instance.applicationContext val context = SPMockBuilder().createContext()
context.sharedPrefs.edit { context.sharedPrefs.edit {
clear() clear()
putBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, true) putBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, true)
@ -109,7 +110,7 @@ class MigrationsTest {
@Test @Test
fun verifyClearClipboardHistoryMigration() { fun verifyClearClipboardHistoryMigration() {
val context = Application.instance.applicationContext val context = SPMockBuilder().createContext()
context.sharedPrefs.edit { context.sharedPrefs.edit {
clear() clear()
putBoolean(PreferenceKeys.CLEAR_CLIPBOARD_20X, true) putBoolean(PreferenceKeys.CLEAR_CLIPBOARD_20X, true)