[Android] ModelsHelper tests almost done

Shivansh Saini git at videolan.org
Mon Dec 16 17:52:39 CET 2019


vlc-android | branch: master | Shivansh Saini <shivanshs9 at gmail.com> | Wed Jul  3 20:00:40 2019 +0530| [c6503e4c1e16a12812bb27c0e160e8fa4aa705f8] | committer: Geoffrey Métais

ModelsHelper tests almost done

> https://code.videolan.org/videolan/vlc-android/commit/c6503e4c1e16a12812bb27c0e160e8fa4aa705f8
---

 .../test/org/videolan/vlc/util/ModelsHelperTest.kt | 127 +++++++++++++++++++++
 1 file changed, 127 insertions(+)

diff --git a/vlc-android/test/org/videolan/vlc/util/ModelsHelperTest.kt b/vlc-android/test/org/videolan/vlc/util/ModelsHelperTest.kt
new file mode 100644
index 000000000..01108b71b
--- /dev/null
+++ b/vlc-android/test/org/videolan/vlc/util/ModelsHelperTest.kt
@@ -0,0 +1,127 @@
+package org.videolan.vlc.util
+
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.ObsoleteCoroutinesApi
+import org.videolan.vlc.BaseTest
+
+import org.junit.Assert.*
+import org.junit.Test
+import org.videolan.medialibrary.MLServiceLocator
+import org.videolan.medialibrary.Medialibrary
+import org.videolan.medialibrary.stubs.StubDataSource
+import org.videolan.vlc.util.ModelsHelper.getHeader
+
+ at ExperimentalCoroutinesApi
+ at ObsoleteCoroutinesApi
+class ModelsHelperTest : BaseTest() {
+    val dataSource: StubDataSource = StubDataSource.getInstance()
+
+    override fun beforeTest() {
+        super.beforeTest()
+        dataSource.resetData()
+    }
+
+    @Test
+    fun withDefaultSortingAndPreviousItemIsNullAndCurrentItemHasNoTitle_headerShouldBeSpecial() {
+        val item = dataSource.createFolder("")
+        assertEquals("#", getHeader(context, Medialibrary.SORT_DEFAULT, item, null))
+    }
+
+    @Test
+    fun withDefaultSortingAndPreviousItemAndCurrentItemHaveSameInitials_headerShouldBeNull() {
+        val item = dataSource.createFolder("abc")
+        val aboveItem = dataSource.createFolder("Adef")
+        assertEquals(null, getHeader(context, Medialibrary.SORT_DEFAULT, item, aboveItem))
+    }
+
+    @Test
+    fun withDefaultSortingAndPreviousItemIsNullAndCurrentItemStartsWithNumber_headerShouldBeSpecial() {
+        val item = dataSource.createFolder("9ab")
+        assertEquals("#", getHeader(context, Medialibrary.SORT_DEFAULT, item, null))
+    }
+
+    @Test
+    fun withDefaultSortingAndPreviousItemAndCurrentItemHaveDifferentInitials_headerShouldBeTheCurrentInitials() {
+        val item = dataSource.createFolder("abc")
+        val aboveItem = dataSource.createFolder("def")
+        assertEquals("A", getHeader(context, Medialibrary.SORT_DEFAULT, item, aboveItem))
+    }
+
+    @Test
+    fun withDefaultSortingAndPreviousItemAndCurrentItemStartWithDifferentNumber_headerShouldBeNull() {
+        val item = dataSource.createFolder("91c")
+        val aboveItem = dataSource.createFolder("7sc")
+        assertEquals(null, getHeader(context, Medialibrary.SORT_DEFAULT, item, aboveItem))
+    }
+
+    @Test
+    fun withDurationSortingAndPreviousItemIsNullAndCurrentItemIsZeroDuration_headerShouldBePlaceholder() {
+        val item = MLServiceLocator.getAbstractAlbum(dataSource.uuid, "Abc", 2018, "Artwork", "Dummy", 9, 1, 0)
+        assertEquals("-", getHeader(context, Medialibrary.SORT_DURATION, item, null))
+    }
+
+    @Test
+    fun withDurationSortingAndPreviousItemIsNullAndCurrentItemIsFolder_headerShouldBePlaceholder() {
+        val item = dataSource.createFolder("abc")
+        assertEquals("-", getHeader(context, Medialibrary.SORT_DURATION, item, null))
+    }
+
+    @Test
+    fun withDurationSortingAndPreviousItemIsNullAndCurrentItemIsAlbum_headerShouldBeLengthToCategory() {
+        val item = MLServiceLocator.getAbstractAlbum(dataSource.uuid, "Abc", 2018, "Artwork", "Dummy", 9, 1, 48000)
+        assertEquals(ModelsHelper.lengthToCategory(item.duration), getHeader(context, Medialibrary.SORT_DURATION, item, null))
+    }
+
+    @Test
+    fun withDurationSortingAndPreviousItemAndCurrentItemAreBothFolder_headerShouldBeNull() {
+        val item = dataSource.createFolder("abc")
+        val aboveItem = dataSource.createFolder("cyz")
+        assertEquals(null, getHeader(context, Medialibrary.SORT_DURATION, item, aboveItem))
+    }
+
+    @Test
+    fun withDurationSortingAndPreviousItemAndCurrentItemAreBothAlbumLessThanMinute_headerShouldBeNull() {
+        val item = MLServiceLocator.getAbstractAlbum(dataSource.uuid, "Abc", 2018, "Artwork", "Dummy", 9, 1, 48000)
+        val aboveItem = MLServiceLocator.getAbstractAlbum(dataSource.uuid, "Abc", 2018, "Artwork", "Dummy", 9, 1, 51000)
+        assertEquals(null, getHeader(context, Medialibrary.SORT_DURATION, item, aboveItem))
+    }
+
+    @Test
+    fun withReleaseDateSortingAndPreviousItemIsNullAndCurrentItemIsFolder_headerShouldBeSpecial() {
+        val item = dataSource.createFolder("test")
+        assertEquals("-", getHeader(context, Medialibrary.SORT_RELEASEDATE, item, null))
+    }
+
+    @Test
+    fun withReleaseDateSortingAndPreviousItemIsNullAndCurrentItemIsAlbumWithNoDate_headerShouldBeSpecial() {
+        val item = MLServiceLocator.getAbstractAlbum(dataSource.uuid, "Abc", 0, "Artwork", "Dummy", 9, 1, 0)
+        assertEquals("-", getHeader(context, Medialibrary.SORT_RELEASEDATE, item, null))
+    }
+
+    @Test
+    fun withReleaseDateSortingAndPreviousItemIsNullAndCurrentItemIsAlbumWith2019Date_headerShouldBe2019() {
+        val item = MLServiceLocator.getAbstractAlbum(dataSource.uuid, "Abc", 2019, "Artwork", "Dummy", 9, 1, 0)
+        assertEquals("2019", getHeader(context, Medialibrary.SORT_RELEASEDATE, item, null))
+    }
+
+    @Test
+    fun withReleaseDateSortingAndPreviousItemAndCurrentItemAreAlbumWithNoDate_headerShouldBeNull() {
+        val item = MLServiceLocator.getAbstractAlbum(dataSource.uuid, "Abc", 0, "Artwork", "Dummy", 9, 1, 0)
+        val aboveItem = MLServiceLocator.getAbstractAlbum(dataSource.uuid, "dEF", 0, "Artwork", "Dummy", 9, 1, 0)
+        assertEquals(null, getHeader(context, Medialibrary.SORT_RELEASEDATE, item, aboveItem))
+    }
+
+    @Test
+    fun withReleaseDateSortingAndPreviousItemAndCurrentItemAreAlbumWithSameDate_headerShouldBeNull() {
+        val item = MLServiceLocator.getAbstractAlbum(dataSource.uuid, "Abc", 2019, "Artwork", "Dummy", 9, 1, 0)
+        val aboveItem = MLServiceLocator.getAbstractAlbum(dataSource.uuid, "dEF", 2019, "Artwork", "Dummy", 9, 1, 0)
+        assertEquals(null, getHeader(context, Medialibrary.SORT_RELEASEDATE, item, aboveItem))
+    }
+
+    @Test
+    fun withReleaseDateSortingAndPreviousItemIsAlbumWith2020DateAndCurrentItemIsAlbumWith2019Date_headerShouldBe2019() {
+        val item = MLServiceLocator.getAbstractAlbum(dataSource.uuid, "Abc", 2019, "Artwork", "Dummy", 9, 1, 0)
+        val aboveItem = MLServiceLocator.getAbstractAlbum(dataSource.uuid, "dEF", 2020, "Artwork", "Dummy", 9, 1, 0)
+        assertEquals("2019", getHeader(context, Medialibrary.SORT_RELEASEDATE, item, aboveItem))
+    }
+}
\ No newline at end of file



More information about the Android mailing list