Commit cdb1da17 authored by Habib Kazemi's avatar Habib Kazemi Committed by Geoffrey Métais

Use unit-test for repositories instead of instrumentTest

Some modifications in packages also done
Signed-off-by: default avatarGeoffrey Métais <geoffrey.metais@gmail.com>
parent 2c44b57d
......@@ -30,6 +30,8 @@ ext {
roomVersion = '1.1.1'
compileSdkVersion = 26
junitVersion = '4.12'
mockito = '2.8.9'
powerMock = '1.7.4'
espressoVersion = '3.0.1'
supportTest = '1.0.2'
minSdkVersion = 17
......
......@@ -26,14 +26,14 @@ import org.hamcrest.Matchers.*
import org.junit.Test
import org.junit.runner.RunWith
import org.videolan.vlc.util.getValue
import java.org.videolan.vlc.util.TestUtil
import org.videolan.vlc.util.TestUtil
@RunWith(AndroidJUnit4::class)
class BrowserFavDaoTest: DbTest() {
@Test fun insertTwoNetworkAndOneLocal_GetAllShouldReturnThreeFav() {
val fakeNetworkFavs = TestUtil.crateNetworkFavs(2)
val fakeNetworkFavs = TestUtil.createNetworkFavs(2)
val fakeLocalFav = TestUtil.createLocalFavs(1)[0]
fakeNetworkFavs.forEach { db.browserFavDao().insert(it) }
......@@ -50,7 +50,7 @@ class BrowserFavDaoTest: DbTest() {
}
@Test fun insertTwoNetworkAndOneLocal_GetNetworkFavsShouldReturnTwoFav() {
val fakeNetworkFavs = TestUtil.crateNetworkFavs(2)
val fakeNetworkFavs = TestUtil.createNetworkFavs(2)
val fakeLocalFavs = TestUtil.createLocalFavs(1)[0]
fakeNetworkFavs.forEach { db.browserFavDao().insert(it) }
......@@ -67,7 +67,7 @@ class BrowserFavDaoTest: DbTest() {
@Test fun insertTwoNetworkAndTwoLocal_GetLocalFavsShouldReturnTwoFav() {
val fakeNetworkFavs = TestUtil.crateNetworkFavs(2)
val fakeNetworkFavs = TestUtil.createNetworkFavs(2)
val fakeLocalFavs = TestUtil.createLocalFavs(2)
fakeNetworkFavs.forEach { db.browserFavDao().insert(it) }
......@@ -83,7 +83,7 @@ class BrowserFavDaoTest: DbTest() {
}
@Test fun insertTwoNetworkAndTwoLocal_GetFavByUriShouldReturnOneFav() {
val fakeNetworkFavs = TestUtil.crateNetworkFavs(2)
val fakeNetworkFavs = TestUtil.createNetworkFavs(2)
val fakeLocalFavs = TestUtil.createLocalFavs(2)
fakeNetworkFavs.forEach { db.browserFavDao().insert(it) }
......@@ -99,7 +99,7 @@ class BrowserFavDaoTest: DbTest() {
}
@Test fun insertTwoNetworkAndTwoLocal_DeleteOne() {
val fakeNetworkFavs = TestUtil.crateNetworkFavs(2)
val fakeNetworkFavs = TestUtil.createNetworkFavs(2)
val fakeLocalFavs = TestUtil.createLocalFavs(2)
fakeNetworkFavs.forEach { db.browserFavDao().insert(it) }
......@@ -115,7 +115,7 @@ class BrowserFavDaoTest: DbTest() {
}
@Test fun insertTwoNetworkAndTwoLocal_DeleteAll() {
val fakeNetworkFavs = TestUtil.crateNetworkFavs(2)
val fakeNetworkFavs = TestUtil.createNetworkFavs(2)
val fakeLocalFavs = TestUtil.createLocalFavs(2)
fakeNetworkFavs.forEach { db.browserFavDao().insert(it) }
......
......@@ -25,7 +25,7 @@ import org.hamcrest.Matchers.*
import org.junit.Assert.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import java.org.videolan.vlc.util.TestUtil
import org.videolan.vlc.util.TestUtil
@RunWith(AndroidJUnit4::class)
class ExternalSubDaoTest: DbTest() {
......
......@@ -25,7 +25,7 @@ import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.*
import org.junit.Test
import org.junit.runner.RunWith
import java.org.videolan.vlc.util.TestUtil
import org.videolan.vlc.util.TestUtil
@RunWith(AndroidJUnit4::class)
class SlaveDaoTest: DbTest() {
......
/*******************************************************************************
* ExternalSubRepositoryTest.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.repository
import android.arch.persistence.room.Room
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import kotlinx.coroutines.experimental.runBlocking
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.videolan.vlc.database.MediaDatabase
import java.io.File
@RunWith(AndroidJUnit4::class)
class ExternalSubRepositoryTest {
private lateinit var database: MediaDatabase
private lateinit var externalSubRepository: ExternalSubRepository
private val media1Name = "file1.mkv"
private val subsFolder = "/storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/"
private val file1Sub1 = "${subsFolder}file1.eng.srt"
private val file1Sub2 = "${subsFolder}file1.fa.srt"
private val file1Sub3 = "${subsFolder}file1.fr.srt"
@Before
fun onCreateRepository() {
val context = InstrumentationRegistry.getTargetContext()
database = Room.inMemoryDatabaseBuilder(context, MediaDatabase::class.java).build()
externalSubRepository = ExternalSubRepository(context, mediaDatabase = database)
val subsFolder = File(subsFolder)
subsFolder.mkdirs()
}
@After fun clean() {
val subsFolder = File(subsFolder)
subsFolder.deleteRecursively()
}
@Test fun saveSubtitle() = runBlocking{
externalSubRepository.saveSubtitle(file1Sub1, media1Name)
externalSubRepository.saveSubtitle(file1Sub2, media1Name)
externalSubRepository.saveSubtitle(file1Sub3, media1Name)
val file1 = File(file1Sub1)
file1.createNewFile()
val file2 = File(file1Sub2)
file2.createNewFile()
val file3 = File(file1Sub3)
file3.createNewFile()
val externalSubs = externalSubRepository.getSubtitles(media1Name)
assertThat(externalSubs.size, equalTo(3))
file1.delete()
var externalSubsAfterDelete = externalSubRepository.getSubtitles(media1Name)
assertThat(externalSubsAfterDelete.size, equalTo(2))
file2.delete()
externalSubsAfterDelete = externalSubRepository.getSubtitles(media1Name)
assertThat(externalSubsAfterDelete.size, equalTo(1))
file3.delete()
externalSubsAfterDelete = externalSubRepository.getSubtitles(media1Name)
assertThat(externalSubsAfterDelete.size, equalTo(0))
}
}
\ No newline at end of file
/*******************************************************************************
* SlaveRepositoryTest.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.repository
import android.arch.persistence.room.Room
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import junit.framework.Assert.assertEquals
import kotlinx.coroutines.experimental.runBlocking
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.videolan.libvlc.Media
import org.videolan.vlc.database.MediaDatabase
@RunWith(AndroidJUnit4::class)
class SlaveRepositoryTest {
private lateinit var database: MediaDatabase
private lateinit var slaveRepository: SlaveRepository
val media1Path = "/storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file1.mkv"
val media1UriEng = "file:///storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file1.eng.srt"
val media1UriFa = "file:///storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file1.fa.srt"
val media2Path = "/storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file2.mkv"
val media2UriEng = "file:///storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file2.eng.srt"
@Before fun onCreateRepository() {
val context = InstrumentationRegistry.getTargetContext()
database = Room.inMemoryDatabaseBuilder(context, MediaDatabase::class.java).build()
slaveRepository = SlaveRepository(context, mediaDatabase = database)
}
@After fun closeDb() {
database.close()
}
@Test fun saveSlave() = runBlocking {
val slavesBeforeInsert = slaveRepository.getSlaves(media1Path)
assertThat(slavesBeforeInsert.size, equalTo(0))
slaveRepository.saveSlave(media1Path, Media.Slave.Type.Subtitle, 2, media1UriEng).join()
slaveRepository.saveSlave(media1Path, Media.Slave.Type.Subtitle, 2, media1UriFa).join()
val slavesAfterInsert = slaveRepository.getSlaves(media1Path)
assertThat(slavesAfterInsert.size, equalTo(1))
}
@Test fun getSlaves() = runBlocking{
slaveRepository.saveSlave(media1Path, Media.Slave.Type.Subtitle, 2, media1UriEng).join()
val correctMediSlave = Media.Slave(Media.Slave.Type.Subtitle, 2, media1UriEng)
val slaves = slaveRepository.getSlaves(media1Path)
assertEquals(slaves[0].uri, correctMediSlave.uri)
assertEquals(slaves[0].type, correctMediSlave.type)
assertEquals(slaves[0].priority, correctMediSlave.priority)
}
}
\ No newline at end of file
......@@ -74,6 +74,9 @@ android {
testOptions {
execution 'ANDROID_TEST_ORCHESTRATOR'
unitTests {
includeAndroidResources = true
}
}
signingConfigs {
......@@ -235,6 +238,9 @@ dependencies {
androidTestImplementation "android.arch.core:core-testing:$rootProject.ext.archVersion"
androidTestImplementation "com.android.support.test:runner:$rootProject.ext.supportTest"
androidTestUtil "com.android.support.test:orchestrator:$rootProject.ext.supportTest"
testImplementation "org.mockito:mockito-core:$rootProject.ext.mockito"
testImplementation "org.powermock:powermock-api-mockito2:$rootProject.ext.powerMock"
testImplementation "org.powermock:powermock-module-junit4:$rootProject.ext.powerMock"
}
......
......@@ -178,7 +178,7 @@ val migration_26_27 = object:Migration(26, 27) {
}
fun populateDB(context: Context) = launch(VLCIO) {
val favRepo = BrowserFavRepository(context)
val favRepo = BrowserFavRepository(MediaDatabase.getDatabase(context).browserFavDao())
val uris = listOf(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MOVIES_DIRECTORY_URI,
AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MUSIC_DIRECTORY_URI,
AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_PODCAST_DIRECTORY_URI,
......
......@@ -45,6 +45,7 @@ import kotlinx.coroutines.experimental.withContext
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.R
import org.videolan.vlc.database.MediaDatabase
import org.videolan.vlc.databinding.DirectoryBrowserBinding
import org.videolan.vlc.gui.InfoActivity
import org.videolan.vlc.gui.dialogs.CtxActionReceiver
......@@ -105,7 +106,7 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
}
showHiddenFiles = PreferenceManager.getDefaultSharedPreferences(requireContext()).getBoolean("browser_show_hidden_files", false)
isRootDirectory = defineIsRoot()
browserFavRepository = BrowserFavRepository(requireContext())
browserFavRepository = BrowserFavRepository(MediaDatabase.getDatabase(requireContext()).browserFavDao())
}
override fun onPrepareOptionsMenu(menu: Menu?) {
......
......@@ -24,6 +24,7 @@ import android.widget.TextView;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.R;
import org.videolan.vlc.database.MediaDatabase;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.repository.BrowserFavRepository;
import org.videolan.vlc.util.WorkersKt;
......@@ -77,7 +78,7 @@ public class NetworkServerDialog extends DialogFragment implements AdapterView.O
public void onAttach(Activity activity) {
super.onAttach(activity);
mActivity = activity;
mBrowserFavRepository = new BrowserFavRepository(requireContext());
mBrowserFavRepository = new BrowserFavRepository( MediaDatabase.Companion.getDatabase(requireContext()).browserFavDao());
}
@Override
......
......@@ -44,6 +44,7 @@ import org.videolan.vlc.BuildConfig
import org.videolan.vlc.ExternalMonitor
import org.videolan.vlc.R
import org.videolan.vlc.RecommendationsService
import org.videolan.vlc.database.MediaDatabase
import org.videolan.vlc.gui.preferences.PreferencesFragment
import org.videolan.vlc.gui.tv.MainTvActivity.ACTIVITY_RESULT_PREFERENCES
import org.videolan.vlc.gui.tv.MainTvActivity.BROWSER_TYPE
......@@ -107,7 +108,7 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
backgroundManager = BackgroundManager.getInstance(requireActivity()).apply { attach(requireActivity().window) }
nowPlayingDelegate = NowPlayingDelegate(this)
browserFavRepository = BrowserFavRepository(requireContext())
browserFavRepository = BrowserFavRepository(MediaDatabase.getDatabase(requireContext()).browserFavDao())
favorites = browserFavRepository.networkFavorites
favorites.observe(this, Observer{
it?.let{
......
......@@ -46,6 +46,7 @@ import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.PlaybackService;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.database.MediaDatabase;
import org.videolan.vlc.gui.PlaybackServiceFragment;
import org.videolan.vlc.gui.helpers.AudioUtil;
import org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity;
......@@ -81,7 +82,7 @@ public class MediaItemDetailsFragment extends DetailsFragment implements Playbac
super.onCreate(savedInstanceState);
mBackgroundManager = BackgroundManager.getInstance(getActivity());
mBackgroundManager.setAutoReleaseOnStop(false);
mBrowserFavRepository = new BrowserFavRepository(VLCApplication.getAppContext());
mBrowserFavRepository = new BrowserFavRepository(MediaDatabase.Companion.getDatabase(VLCApplication.getAppContext()).browserFavDao());
buildDetails();
}
......
......@@ -108,6 +108,7 @@ import org.videolan.vlc.PlaybackService;
import org.videolan.vlc.R;
import org.videolan.vlc.RendererDelegate;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.database.MediaDatabase;
import org.videolan.vlc.databinding.PlayerHudBinding;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.PlaybackServiceActivity;
......@@ -849,7 +850,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
if(data.hasExtra(FilePickerFragment.EXTRA_MRL)) {
mService.addSubtitleTrack(Uri.parse(data.getStringExtra(FilePickerFragment.EXTRA_MRL)), true);
new SlaveRepository(getApplicationContext()).saveSlave(mService.getCurrentMediaLocation(), Media.Slave.Type.Subtitle, 2, data.getStringExtra(FilePickerFragment.EXTRA_MRL));
new SlaveRepository(MediaDatabase.Companion.getDatabase(getApplicationContext()).slaveDao()).saveSlave(mService.getCurrentMediaLocation(), Media.Slave.Type.Subtitle, 2, data.getStringExtra(FilePickerFragment.EXTRA_MRL));
} else if (BuildConfig.DEBUG) Log.d(TAG, "Subtitle selection dialog was cancelled");
}
......@@ -2882,7 +2883,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
final MediaWrapper mw = mService.getCurrentMediaWrapper();
if (mw != null) mediaTitle = FileUtils.getFileNameFromPath(mService.getCurrentMediaWrapper().getLocation());
}
if (mediaTitle != null) prefsList.addAll(new ExternalSubRepository(getApplicationContext()).getSubtitles(mediaTitle));
if (mediaTitle != null) prefsList.addAll(new ExternalSubRepository(MediaDatabase.Companion.getDatabase(getApplicationContext()).externalSubDao()).getSubtitles(mediaTitle));
return prefsList;
}
......
......@@ -14,6 +14,7 @@ import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.RendererDelegate
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.database.MediaDatabase
import org.videolan.vlc.gui.preferences.PreferencesActivity
import org.videolan.vlc.repository.SlaveRepository
import org.videolan.vlc.util.VLCInstance
......@@ -27,7 +28,7 @@ class PlayerController : IVLCVout.Callback, MediaPlayer.EventListener {
private val playerContext by lazy(LazyThreadSafetyMode.NONE) { newSingleThreadContext("vlc-player") }
private val settings by lazy(LazyThreadSafetyMode.NONE) { VLCApplication.getSettings() }
val progress by lazy(LazyThreadSafetyMode.NONE) { MutableLiveData<Progress>().apply { value = Progress() } }
private val slaveRepository by lazy { SlaveRepository(VLCApplication.getAppContext()) }
private val slaveRepository by lazy { SlaveRepository(MediaDatabase.getDatabase(VLCApplication.getAppContext()).slaveDao()) }
private var mediaplayer = newMediaPlayer()
var switchToVideo = false
......
......@@ -36,6 +36,7 @@ import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.ExternalMonitor
import org.videolan.vlc.R
import org.videolan.vlc.database.MediaDatabase
import org.videolan.vlc.database.models.BrowserFav
import org.videolan.vlc.gui.helpers.hf.getDocumentFiles
import org.videolan.vlc.repository.BrowserFavRepository
......@@ -53,7 +54,7 @@ open class FileBrowserProvider(
private var storagePosition = -1
private var otgPosition = -1
private val showFavorites : Boolean
private val favorites = if (url == null && !filePicker) BrowserFavRepository(context).localFavorites else null
private val favorites = if (url == null && !filePicker) BrowserFavRepository(MediaDatabase.getDatabase(context).browserFavDao()).localFavorites else null
private val favoritesObserver by lazy { Observer<List<BrowserFav>> {
val favs = convertFavorites(it)
......
......@@ -28,12 +28,13 @@ import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.ExternalMonitor
import org.videolan.vlc.R
import org.videolan.vlc.database.MediaDatabase
import org.videolan.vlc.repository.BrowserFavRepository
import org.videolan.vlc.util.LiveDataset
class NetworkProvider(context: Context, dataset: LiveDataset<MediaLibraryItem>, url: String? = null, showHiddenFiles: Boolean): BrowserProvider(context, dataset, url, showHiddenFiles), Observer<List<MediaWrapper>> {
private val favorites = if (url == null) BrowserFavRepository(context).networkFavorites else null
private val favorites = if (url == null) BrowserFavRepository(MediaDatabase.getDatabase(context).browserFavDao()).networkFavorites else null
init {
favorites?.observeForever(this)
......
......@@ -21,7 +21,6 @@
package org.videolan.vlc.repository
import android.arch.lifecycle.MediatorLiveData
import android.content.Context
import android.net.Uri
import android.support.annotation.WorkerThread
import kotlinx.coroutines.experimental.android.UI
......@@ -29,7 +28,6 @@ import kotlinx.coroutines.experimental.launch
import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.ExternalMonitor
import org.videolan.vlc.database.BrowserFavDao
import org.videolan.vlc.database.MediaDatabase
import org.videolan.vlc.database.models.BrowserFav
import org.videolan.vlc.util.Constants.TYPE_LOCAL_FAV
import org.videolan.vlc.util.Constants.TYPE_NETWORK_FAV
......@@ -38,11 +36,7 @@ import org.videolan.vlc.util.convertFavorites
import java.util.*
class BrowserFavRepository @JvmOverloads constructor(context: Context,
val mediaDatabase: MediaDatabase = MediaDatabase.getDatabase(context),
private val browserFavDao: BrowserFavDao = mediaDatabase.browserFavDao()
) {
class BrowserFavRepository(private val browserFavDao: BrowserFavDao) {
private val networkFavs by lazy { browserFavDao.getAllNetwrokFavs() }
......
......@@ -20,23 +20,14 @@
package org.videolan.vlc.repository
import android.content.Context
import android.net.Uri
import android.support.annotation.WorkerThread
import kotlinx.coroutines.experimental.Job
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.withContext
import org.videolan.vlc.database.MediaDatabase
import org.videolan.vlc.database.models.ExternalSub
import org.videolan.vlc.database.ExternalSubDao
import org.videolan.vlc.util.VLCIO
import java.io.File
class ExternalSubRepository @JvmOverloads constructor(context: Context,
val mediaDatabase: MediaDatabase = MediaDatabase.getDatabase(context),
val externalSubDao: ExternalSubDao = mediaDatabase.externalSubDao()
) {
class ExternalSubRepository(val externalSubDao: ExternalSubDao ) {
fun saveSubtitle(path: String, mediaName: String) {
externalSubDao.insert(ExternalSub(path, mediaName))
}
......
......@@ -32,10 +32,8 @@ import org.videolan.vlc.database.SlaveDao
import org.videolan.vlc.database.models.Slave
import org.videolan.vlc.util.VLCIO
class SlaveRepository @JvmOverloads constructor(context: Context,
val mediaDatabase:MediaDatabase = MediaDatabase.getDatabase(context),
val slaveDao:SlaveDao = mediaDatabase.slaveDao()
){
class SlaveRepository(val slaveDao:SlaveDao){
fun saveSlave(mediaPath: String, type: Int, priority: Int, uriString: String): Job {
return launch(VLCIO) {
......
......@@ -46,6 +46,7 @@ import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.BuildConfig;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.database.MediaDatabase;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.gui.video.VideoPlayerActivity;
import org.videolan.vlc.repository.ExternalSubRepository;
......@@ -345,7 +346,7 @@ public class SubtitlesDownloader {
while ((length = gzIS.read(buffer)) != -1) {
f.write(buffer, 0, length);
}
new ExternalSubRepository(VLCApplication.getAppContext()).saveSubtitle(srtUrl, fileName);
new ExternalSubRepository(MediaDatabase.Companion.getDatabase(VLCApplication.getAppContext()).externalSubDao()).saveSubtitle(srtUrl, fileName);
} catch (Throwable e) { //for various service outages
if (BuildConfig.DEBUG) Log.e(TAG, "download fail", e);
} finally {
......
/*******************************************************************************
* MockitoExt.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.util
import org.mockito.ArgumentCaptor
import org.mockito.Mockito
/**
* a kotlin friendly mock that handles generics
*/
inline fun <reified T> mock(): T = Mockito.mock(T::class.java)
inline fun <reified T> argumentCaptor(): ArgumentCaptor<T> = ArgumentCaptor.forClass(T::class.java)
fun <T> uninitialized(): T = null as T
......@@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package java.org.videolan.vlc.util
package org.videolan.vlc.util
import android.net.Uri
import org.videolan.libvlc.Media
......@@ -36,10 +36,16 @@ object TestUtil {
return BrowserFav(uri, Constants.TYPE_LOCAL_FAV, title, iconUrl)
}
fun createLocalUris(count: Int): List<String> {
return (0 until count).map {
"${fakeUri}_local$it"
}
}
fun createLocalFavs(count: Int): List<BrowserFav> {
return (0 until count).map {
createLocalFav(Uri.parse(fakeUri + "local" + it),
"foo" + 1,
"local" + 1,
null)
}
}
......@@ -48,11 +54,17 @@ object TestUtil {
return BrowserFav(uri, Constants.TYPE_NETWORK_FAV, title, iconUrl)
}
fun crateNetworkFavs(count: Int): List<BrowserFav> {
fun createNetworkUris(count: Int): List<String> {
return (0 until count).map {
"${fakeUri}_network$it"
}
}
fun createNetworkFavs(count: Int): List<BrowserFav> {
return (0 until count).map {
createNetworkFav(
Uri.parse(fakeUri + "network" + it),
"foo" + 1,
"network" + 1,
null)