Introduce NewPipeFileLocator class
This commit is contained in:
parent
f778c48923
commit
8fceffd6fd
2 changed files with 9 additions and 14 deletions
|
@ -46,9 +46,7 @@ class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) {
|
|||
}
|
||||
|
||||
|
||||
fun extractDb(
|
||||
filePath: String,
|
||||
): Boolean {
|
||||
fun extractDb(filePath: String): Boolean {
|
||||
val success = ZipHelper.extractFileFromZip(filePath, fileLocator.db.path, "newpipe.db")
|
||||
if (success) {
|
||||
fileLocator.dbJournal.delete()
|
||||
|
@ -59,16 +57,12 @@ class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) {
|
|||
return success
|
||||
}
|
||||
|
||||
fun containSettings(
|
||||
filePath: String,
|
||||
): Boolean {
|
||||
fun containSettings(filePath: String): Boolean {
|
||||
return ZipHelper
|
||||
.extractFileFromZip(filePath, fileLocator.settings.path, "newpipe.settings")
|
||||
}
|
||||
|
||||
fun loadSharedPreferences(
|
||||
preferences: SharedPreferences,
|
||||
) {
|
||||
fun loadSharedPreferences(preferences: SharedPreferences) {
|
||||
try {
|
||||
val preferenceEditor = preferences.edit()
|
||||
|
||||
|
|
|
@ -19,14 +19,14 @@ import org.mockito.Mockito.atLeastOnce
|
|||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.withSettings
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
import org.schabi.newpipe.settings.ContentSettingsManagerTest.ExportTest
|
||||
import org.schabi.newpipe.settings.ContentSettingsManagerTest.*
|
||||
import java.io.File
|
||||
import java.io.ObjectInputStream
|
||||
import java.nio.file.Files
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
@RunWith(Suite::class)
|
||||
@Suite.SuiteClasses(ExportTest::class)
|
||||
@Suite.SuiteClasses(ExportTest::class, ImportTest::class)
|
||||
class ContentSettingsManagerTest {
|
||||
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
|
@ -73,23 +73,24 @@ class ContentSettingsManagerTest {
|
|||
|
||||
val zipFile = ZipFile(output.absoluteFile)
|
||||
val entries = zipFile.entries().toList()
|
||||
Assert.assertEquals(2, entries.size)
|
||||
assertEquals(2, entries.size)
|
||||
|
||||
zipFile.getInputStream(entries.first { it.name == "newpipe.db" }).use { actual ->
|
||||
newpipeDb.inputStream().use { expected ->
|
||||
Assert.assertEquals(expected.reader().readText(), actual.reader().readText())
|
||||
assertEquals(expected.reader().readText(), actual.reader().readText())
|
||||
}
|
||||
}
|
||||
|
||||
zipFile.getInputStream(entries.first { it.name == "newpipe.settings" }).use { actual ->
|
||||
val actualPreferences = ObjectInputStream(actual).readObject()
|
||||
Assert.assertEquals(expectedPreferences, actualPreferences)
|
||||
assertEquals(expectedPreferences, actualPreferences)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class ImportTest {
|
||||
|
||||
companion object {
|
||||
private lateinit var fileLocator: NewPipeFileLocator
|
||||
private lateinit var zip: File
|
||||
|
|
Loading…
Reference in a new issue