ModelsHelperTest.kt 5.93 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 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

@ExperimentalCoroutinesApi
@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))
    }
}