From ea91a62c89e70fc392c811af5dbcea34a9064035 Mon Sep 17 00:00:00 2001 From: XiangRongLin <41164160+XiangRongLin@users.noreply.github.com> Date: Sat, 19 Dec 2020 14:10:10 +0100 Subject: [PATCH] Adjust ExportTest to new DI with FileLocator --- app/build.gradle | 4 +++- .../org/schabi/newpipe/settings/ContentSettingsManager.kt | 2 +- .../schabi/newpipe/settings/ContentSettingsManagerTest.kt | 8 +++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9fb9cf85f..b3c6f6bad 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -102,6 +102,7 @@ ext { groupieVersion = '2.8.1' markwonVersion = '4.6.0' googleAutoServiceVersion = '1.0-rc7' + mockitoVersion = '3.6.0' } configurations { @@ -235,7 +236,8 @@ dependencies { implementation "org.ocpsoft.prettytime:prettytime:4.0.6.Final" testImplementation 'junit:junit:4.13.1' - testImplementation 'org.mockito:mockito-core:3.6.0' + testImplementation "org.mockito:mockito-core:${mockitoVersion}" + testImplementation "org.mockito:mockito-inline:${mockitoVersion}" androidTestImplementation "androidx.test.ext:junit:1.1.2" androidTestImplementation "androidx.room:room-testing:${androidxRoomVersion}" diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsManager.kt b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsManager.kt index 5e92f59bf..f278c6b24 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsManager.kt +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsManager.kt @@ -21,7 +21,7 @@ class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) { fun exportDatabase(preferences: SharedPreferences, outputPath: String) { ZipOutputStream(BufferedOutputStream(FileOutputStream(outputPath))) .use { outZip -> - ZipHelper.addFileToZip(outZip, fileLocator.dbDir.path, "newpipe.db") + ZipHelper.addFileToZip(outZip, fileLocator.db.path, "newpipe.db") try { ObjectOutputStream(FileOutputStream(fileLocator.settings)).use { output -> diff --git a/app/src/test/java/org/schabi/newpipe/settings/ContentSettingsManagerTest.kt b/app/src/test/java/org/schabi/newpipe/settings/ContentSettingsManagerTest.kt index 5ac132f7f..67895fc7c 100644 --- a/app/src/test/java/org/schabi/newpipe/settings/ContentSettingsManagerTest.kt +++ b/app/src/test/java/org/schabi/newpipe/settings/ContentSettingsManagerTest.kt @@ -1,6 +1,7 @@ package org.schabi.newpipe.settings import android.content.SharedPreferences +import com.nononsenseapps.filepicker.NewFolderFragment import org.junit.Assert import org.junit.Assume import org.junit.Before @@ -24,6 +25,7 @@ class ContentSettingsManagerTest { class ExportTest { companion object { + private lateinit var fileLocator: NewPipeFileLocator private lateinit var newpipeDb: File private lateinit var newpipeSettings: File @@ -37,6 +39,10 @@ class ContentSettingsManagerTest { newpipeDb = File(dbPath!!) newpipeSettings = File(settingsPath!!) + + fileLocator = Mockito.mock(NewPipeFileLocator::class.java, Mockito.withSettings().stubOnly()) + `when`(fileLocator.db).thenReturn(newpipeDb) + `when`(fileLocator.settings).thenReturn(newpipeSettings) } } @@ -52,7 +58,7 @@ class ContentSettingsManagerTest { val expectedPreferences = mapOf("such pref" to "much wow") `when`(preferences.all).thenReturn(expectedPreferences) - val manager = ContentSettingsManager(newpipeDb, newpipeSettings) + val manager = ContentSettingsManager(fileLocator) val output = File.createTempFile("newpipe_", "") manager.exportDatabase(preferences, output.absolutePath)