1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 08:30:44 +00:00

Adjust ExportTest to new DI with FileLocator

This commit is contained in:
XiangRongLin 2020-12-19 14:10:10 +01:00
parent cef791ba1b
commit ea91a62c89
3 changed files with 11 additions and 3 deletions

View File

@ -102,6 +102,7 @@ ext {
groupieVersion = '2.8.1' groupieVersion = '2.8.1'
markwonVersion = '4.6.0' markwonVersion = '4.6.0'
googleAutoServiceVersion = '1.0-rc7' googleAutoServiceVersion = '1.0-rc7'
mockitoVersion = '3.6.0'
} }
configurations { configurations {
@ -235,7 +236,8 @@ dependencies {
implementation "org.ocpsoft.prettytime:prettytime:4.0.6.Final" implementation "org.ocpsoft.prettytime:prettytime:4.0.6.Final"
testImplementation 'junit:junit:4.13.1' 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.test.ext:junit:1.1.2"
androidTestImplementation "androidx.room:room-testing:${androidxRoomVersion}" androidTestImplementation "androidx.room:room-testing:${androidxRoomVersion}"

View File

@ -21,7 +21,7 @@ class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) {
fun exportDatabase(preferences: SharedPreferences, outputPath: String) { fun exportDatabase(preferences: SharedPreferences, outputPath: String) {
ZipOutputStream(BufferedOutputStream(FileOutputStream(outputPath))) ZipOutputStream(BufferedOutputStream(FileOutputStream(outputPath)))
.use { outZip -> .use { outZip ->
ZipHelper.addFileToZip(outZip, fileLocator.dbDir.path, "newpipe.db") ZipHelper.addFileToZip(outZip, fileLocator.db.path, "newpipe.db")
try { try {
ObjectOutputStream(FileOutputStream(fileLocator.settings)).use { output -> ObjectOutputStream(FileOutputStream(fileLocator.settings)).use { output ->

View File

@ -1,6 +1,7 @@
package org.schabi.newpipe.settings package org.schabi.newpipe.settings
import android.content.SharedPreferences import android.content.SharedPreferences
import com.nononsenseapps.filepicker.NewFolderFragment
import org.junit.Assert import org.junit.Assert
import org.junit.Assume import org.junit.Assume
import org.junit.Before import org.junit.Before
@ -24,6 +25,7 @@ class ContentSettingsManagerTest {
class ExportTest { class ExportTest {
companion object { companion object {
private lateinit var fileLocator: NewPipeFileLocator
private lateinit var newpipeDb: File private lateinit var newpipeDb: File
private lateinit var newpipeSettings: File private lateinit var newpipeSettings: File
@ -37,6 +39,10 @@ class ContentSettingsManagerTest {
newpipeDb = File(dbPath!!) newpipeDb = File(dbPath!!)
newpipeSettings = File(settingsPath!!) 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") val expectedPreferences = mapOf("such pref" to "much wow")
`when`(preferences.all).thenReturn(expectedPreferences) `when`(preferences.all).thenReturn(expectedPreferences)
val manager = ContentSettingsManager(newpipeDb, newpipeSettings) val manager = ContentSettingsManager(fileLocator)
val output = File.createTempFile("newpipe_", "") val output = File.createTempFile("newpipe_", "")
manager.exportDatabase(preferences, output.absolutePath) manager.exportDatabase(preferences, output.absolutePath)