FakeMusicCatalogBuilder
Test catalog to perform tests with the FakeMusic media source.
This class is used to define a DSL to generate a customized item hierarchy, representing a media source's media item browsing tree: a media catalog. Its purpose is to tailor the FakeMusic media source's contents for running a specific test.
Once created with the FakeMusicCatalogBuilder.define function, a catalog is ready to be passed to the FakeMusicMediaSourceController.setCatalog to be applied to the FakeMusic media source.
All types of media content can be created with the various functions in FakeMusicCatalogBuilder.
An example of such hierarchy follows:
var myTestPlaylist: List<IviMediaItem> = emptyList()
var myTestSong: IviMediaItem? = null
var myTestIds: List<String> = emptyList()
FakeMusicCatalogBuilder.define(context) {
category("category", "Moods") {
icon = FakeMusicCatalogIcon.MOOD
playlist("pl", "some playlist") {
playable(MY_ID_1, "stairway to heaven") { metadata ->
metadata.withDurationMs(100_000L)
metadata.withArtist("LED zeppelin")
metadata.withBrowsableHint(ContentStyle.CATEGORY_GRID)
}
playable(MY_ID_2, "immigrant song") { metadata ->
metadata.withDurationMs(50_000L)
metadata.withArtist("LCD zeppelin")
metadata.withUserRating(IviMediaRating(Type.THUMBS, RATING_THUMB_DOWN))
}
myTestSong = playable("id", "title") { metadata ->
metadata.withWriter("me")
}
myTestPlaylist = generateTracks(10)
}
browsable("album", "Album") {
playable("track1", "Track One") { it.withDurationMs(1_000L) }
playable("track2", "Track Two") { it.withDurationMs(20_000L) }
myTestIds = childIds
}
}
category("another category", "Unknown") {
playable("mistery", "Mistery Song") { it.withDurationMs(200_000_000L) }
}
}
In the example it is shown how the variables myTestPlaylist
and myTestSong
can be used to retrieve the contents of the catalog while being created, to help comparing test results with the expected catalog contents. In the same way, myTestIds
holds the IviMediaItem.id of all items created up to that moment inside a certain parent item.
It is allowed to generate all sorts of invalid contents, such as empty root items, non-browsable items containing items, invalid metadata.
Constructors
Types
Properties
Functions
Create a browsable only media item.
Convert this item to a FakeMusicCatalogItem for export to the FakeMusic media source.
Add a category to the catalog.
Generate count playable media items as children of this item.
Create a media item which is not playable nor browsable.
Create a playable only media item.
Create a browsable and playable media item.