mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 23:32:59 +00:00 
			
		
		
		
	Fix ensureDbDirectoryExists
This commit is contained in:
		| @@ -45,10 +45,9 @@ class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) { | ||||
|      * @return Whether the directory exists afterwards. | ||||
|      */ | ||||
|     fun ensureDbDirectoryExists(): Boolean { | ||||
|         return !fileLocator.dbDir.exists() && !fileLocator.dbDir.mkdir() | ||||
|         return fileLocator.dbDir.exists() || fileLocator.dbDir.mkdir() | ||||
|     } | ||||
|  | ||||
|  | ||||
|     fun extractDb(filePath: String): Boolean { | ||||
|         val success = ZipHelper.extractFileFromZip(filePath, fileLocator.db.path, "newpipe.db") | ||||
|         if (success) { | ||||
|   | ||||
| @@ -4,6 +4,7 @@ import android.content.SharedPreferences | ||||
| import org.junit.Assert.assertEquals | ||||
| import org.junit.Assert.assertFalse | ||||
| import org.junit.Assert.assertTrue | ||||
| import org.junit.Assume | ||||
| import org.junit.Before | ||||
| import org.junit.Test | ||||
| import org.junit.runner.RunWith | ||||
| @@ -85,6 +86,25 @@ class ContentSettingsManagerTest { | ||||
|         assertFalse(settings.exists()) | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     fun `Ensuring db directory existence must work`() { | ||||
|         val dir = Files.createTempDirectory("newpipe_").toFile() | ||||
|         Assume.assumeTrue(dir.delete()) | ||||
|         `when`(fileLocator.dbDir).thenReturn(dir) | ||||
|  | ||||
|         ContentSettingsManager(fileLocator).ensureDbDirectoryExists() | ||||
|         assertTrue(dir.exists()) | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     fun `Ensuring db directory existence must work when the directory already exists`() { | ||||
|         val dir = Files.createTempDirectory("newpipe_").toFile() | ||||
|         `when`(fileLocator.dbDir).thenReturn(dir) | ||||
|  | ||||
|         ContentSettingsManager(fileLocator).ensureDbDirectoryExists() | ||||
|         assertTrue(dir.exists()) | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     fun `The database must be extracted from the zip file`() { | ||||
|         val db = File.createTempFile("newpipe_", "") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 XiangRongLin
					XiangRongLin