Commit ddf76f2c authored by Shivansh Saini's avatar Shivansh Saini

Test for VideosViewModel done

parent a4bf2b95
......@@ -32,6 +32,12 @@ import static org.videolan.medialibrary.interfaces.AbstractMedialibrary.SORT_LAS
import static org.videolan.medialibrary.interfaces.AbstractMedialibrary.SORT_RELEASEDATE;
public class StubDataSource {
public static final String STUBBED_VIDEO_TITLE = "Invincible";
public static final String STUBBED_AUDIO_TITLE = "Show Me The Way";
public static final String STUBBED_VIDEO_EXTENSION = ".mp4";
public static final String STUBBED_AUDIO_EXTENSION = ".mp3";
ArrayList<AbstractMediaWrapper> mVideoMediaWrappers = new ArrayList<>();
ArrayList<AbstractMediaWrapper> mAudioMediaWrappers = new ArrayList<>();
......@@ -76,7 +82,7 @@ public class StubDataSource {
String fileName;
for (int i = 0; i < count; i++) {
fileName = i + "58_foar_everywun_frum_boxxy.flv";
fileName = i + " - " + STUBBED_VIDEO_TITLE + STUBBED_AUDIO_EXTENSION;
String mrl = baseMrl + ((folder != null) ? folder + "/" : "") + fileName;
media = MLServiceLocator.getAbstractMediaWrapper(getUUID(), mrl, 0L, 18820L, AbstractMediaWrapper.TYPE_VIDEO,
fileName, fileName, "", "",
......@@ -92,7 +98,7 @@ public class StubDataSource {
AbstractMediaWrapper media;
for (int i = 0; i < count; i++) {
fileName = i + "-Show Me The Way.mp3";
fileName = i + " - " + STUBBED_AUDIO_TITLE + STUBBED_AUDIO_EXTENSION;
String mrl = baseMrl + ((folder != null) ? folder + "/" : "") + fileName;
media = MLServiceLocator.getAbstractMediaWrapper(getUUID(), mrl, 0L, 280244L, AbstractMediaWrapper.TYPE_AUDIO,
i + "-Show Me The Way", fileName, "Peter Frampton", "Rock",
......
......@@ -86,6 +86,7 @@ android {
includeAndroidResources = true
}
unitTests.all {
jvmArgs '-noverify'
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
outputs.upToDateWhen { false }
......
......@@ -12,6 +12,7 @@ import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.videolan.libvlc.LibVLC
import org.videolan.libvlc.Media
import org.videolan.libvlc.interfaces.ILibVLC
import org.videolan.libvlc.interfaces.IMedia
import org.videolan.libvlc.stubs.StubMedia
import org.videolan.libvlc.util.MediaBrowser
......@@ -27,7 +28,7 @@ class FilePickerModelTest : BaseTest() {
@get:Rule
val temporaryFolder = TemporaryFolder()
private val mockedLibVlc: LibVLC = mockk(relaxed = true)
private val mockedLibVlc: ILibVLC = mockk(relaxed = true)
private lateinit var dummyUrl: String
private lateinit var mediaBrowser: MediaBrowser
......
......@@ -3,8 +3,7 @@ package org.videolan.vlc.viewmodels.mobile
import com.jraska.livedata.test
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Assert.*
import org.junit.Test
import org.videolan.medialibrary.interfaces.media.AbstractFolder
import org.videolan.medialibrary.stubs.StubDataSource
......@@ -70,7 +69,7 @@ class VideosViewModelTest : BaseTest() {
val testResult = videosViewModel.provider.pagedList.test()
.awaitValue().value()
assertEquals(2, testResult.size)
assertEquals(videoCount, testResult.size)
}
@Test
......@@ -85,7 +84,7 @@ class VideosViewModelTest : BaseTest() {
videosViewModel.provider.pagedList.test()
.awaitValue()
assertEquals(2, videosViewModel.provider.getTotalCount())
assertEquals(videoCount, videosViewModel.provider.getTotalCount())
}
@Test
......@@ -114,4 +113,170 @@ class VideosViewModelTest : BaseTest() {
assertEquals(videoCount, testResult.size)
}
@Test
fun whenFolderIsNullAndItWasEmptyAndAddedNewVideo_checkRefreshUpdatesTheList() {
setupViewModel(null)
videosViewModel.provider.pagedList.test()
.awaitValue()
assertTrue(videosViewModel.isEmpty())
StubDataSource.getInstance().setVideoByCount(1, null)
videosViewModel.refresh()
val testResult = videosViewModel.provider.pagedList.test()
.awaitValue().value()
assertFalse(videosViewModel.isEmpty())
assertEquals(1, testResult.size)
}
@Test
fun whenFolderIsNullAndEmptyAndFiltered_checkResultIsEmpty() {
setupViewModel(null)
videosViewModel.filter("xyz")
videosViewModel.provider.pagedList.test()
.awaitValue()
assertTrue(videosViewModel.isEmpty())
}
@Test
fun whenFolderIsGivenAndEmptyAndFiltered_checkResultIsEmpty() {
setupViewModel(StubDataSource.getInstance().createFolder("test"))
videosViewModel.filter("xyz")
videosViewModel.provider.pagedList.test()
.awaitValue()
assertTrue(videosViewModel.isEmpty())
}
@Test
fun whenFolderIsNullAndNotEmptyAndFilteredWithNonExistingVideo_checkResultIsEmpty() {
setupViewModel(null)
StubDataSource.getInstance().setVideoByCount(3, null)
videosViewModel.provider.pagedList.test()
.awaitValue()
assertFalse(videosViewModel.isEmpty())
videosViewModel.filter("unknown")
videosViewModel.refresh()
videosViewModel.provider.pagedList.test()
.awaitValue()
assertTrue(videosViewModel.isEmpty())
}
@Test
fun whenFolderIsGivenAndNotEmptyAndFilteredWithNonExistingVideo_checkResultIsEmpty() {
setupViewModel(StubDataSource.getInstance().createFolder("test"))
StubDataSource.getInstance().setVideoByCount(3, "test")
videosViewModel.provider.pagedList.test()
.awaitValue()
assertFalse(videosViewModel.isEmpty())
videosViewModel.filter("unknown")
videosViewModel.refresh()
videosViewModel.provider.pagedList.test()
.awaitValue()
assertTrue(videosViewModel.isEmpty())
}
@Test
fun whenFolderIsNullAndNotEmptyAndFilteredWithExistingVideoTitle_checkResultContainsThem() {
setupViewModel(null)
StubDataSource.getInstance().setVideoByCount(3, null)
videosViewModel.provider.pagedList.test()
.awaitValue()
assertFalse(videosViewModel.isEmpty())
videosViewModel.filter(StubDataSource.STUBBED_VIDEO_TITLE.substring(1, 6))
videosViewModel.refresh()
videosViewModel.provider.pagedList.test()
.awaitValue()
assertFalse(videosViewModel.isEmpty())
assertEquals(3, videosViewModel.provider.getTotalCount())
}
@Test
fun whenFolderIsGivenAndNotEmptyAndFilteredWithExistingVideoTitle_checkResultContainsThem() {
setupViewModel(StubDataSource.getInstance().createFolder("test"))
StubDataSource.getInstance().setVideoByCount(3, "test")
videosViewModel.provider.pagedList.test()
.awaitValue()
assertFalse(videosViewModel.isEmpty())
videosViewModel.filter(StubDataSource.STUBBED_VIDEO_TITLE.substring(1, 6))
videosViewModel.refresh()
videosViewModel.provider.pagedList.test()
.awaitValue()
assertFalse(videosViewModel.isEmpty())
assertEquals(3, videosViewModel.provider.getTotalCount())
}
@Test
fun whenFolderIsGivenAndNotEmptyButFilteredResultContainsNone_restoringViewModelResetsFilterAndShowsItemAgain() {
setupViewModel(StubDataSource.getInstance().createFolder("test"))
StubDataSource.getInstance().setVideoByCount(3, "test")
videosViewModel.filter("unknown")
videosViewModel.provider.pagedList.test()
.awaitValue()
assertTrue(videosViewModel.isEmpty())
videosViewModel.restore()
videosViewModel.provider.pagedList.test()
.awaitValue()
assertFalse(videosViewModel.isEmpty())
}
@Test
fun whenFilteredAndLaterRestored_isFilteringIsTrueLaterFalse() {
setupViewModel(null)
StubDataSource.getInstance().setVideoByCount(3, null)
assertFalse(videosViewModel.isFiltering())
videosViewModel.filter(StubDataSource.STUBBED_VIDEO_TITLE.substring(2, 6))
assertTrue(videosViewModel.isFiltering())
videosViewModel.restore()
assertFalse(videosViewModel.isFiltering())
}
@Test
fun whenFolderIsNullAndItHasItems_checkHeaders() {
setupViewModel(null)
StubDataSource.getInstance().setVideoByCount(3, null)
videosViewModel.provider.pagedList.test()
.awaitValue()
val headers = videosViewModel.provider.liveHeaders.test()
.value()
// Can only test with 1 special header, because of limitation of partially-fixed title in stubbed data
assertEquals(1, headers.size())
assertEquals("#", headers[0])
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment