-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,098 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
data/src/test/java/ch/srg/dataProvider/integrationlayer/data/remote/AspectRatioTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package ch.srg.dataProvider.integrationlayer.data.remote | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNotEquals | ||
|
||
class AspectRatioTest { | ||
@Test | ||
fun parse() { | ||
val aspectRatio = AspectRatio.parse("16:9") | ||
|
||
assertEquals(16, aspectRatio.numerator) | ||
assertEquals(9, aspectRatio.denominator) | ||
} | ||
|
||
@Test | ||
fun `parse denominator 0`() { | ||
val aspectRatio = AspectRatio.parse("16:0") | ||
|
||
assertEquals(AspectRatio.Infinity, aspectRatio) | ||
} | ||
|
||
@Test | ||
fun `parse numerator 0`() { | ||
val aspectRatio = AspectRatio.parse("0:9") | ||
|
||
assertEquals(AspectRatio.Zero, aspectRatio) | ||
} | ||
|
||
@Test(expected = IllegalArgumentException::class) | ||
fun `parse empty string`() { | ||
AspectRatio.parse("") | ||
} | ||
|
||
@Test(expected = IllegalArgumentException::class) | ||
fun `parse blank string`() { | ||
AspectRatio.parse(" ") | ||
} | ||
|
||
@Test(expected = IllegalArgumentException::class) | ||
fun `parse invalid string`() { | ||
AspectRatio.parse("hello") | ||
} | ||
|
||
@Test(expected = IllegalArgumentException::class) | ||
fun `parse string with invalid numerator`() { | ||
AspectRatio.parse("abc:9") | ||
} | ||
|
||
@Test(expected = IllegalArgumentException::class) | ||
fun `parse string with invalid denominator`() { | ||
AspectRatio.parse("16:abc") | ||
} | ||
|
||
@Test(expected = IllegalArgumentException::class) | ||
fun `parse string with too many separators`() { | ||
AspectRatio.parse("1:2:3") | ||
} | ||
|
||
@Test | ||
fun `destruction check`() { | ||
val aspectRatio = AspectRatio(16, 9) | ||
val (numerator, denominator) = aspectRatio | ||
|
||
assertEquals(aspectRatio.numerator, numerator) | ||
assertEquals(aspectRatio.denominator, denominator) | ||
} | ||
|
||
@Test | ||
fun `equals check`() { | ||
assertEquals(AspectRatio.Infinity, AspectRatio(1, 0)) | ||
assertEquals(AspectRatio.Zero, AspectRatio(0, 1)) | ||
assertEquals(AspectRatio(16, 9), AspectRatio(16, 9)) | ||
assertNotEquals(AspectRatio(4, 3), AspectRatio(16, 9)) | ||
} | ||
|
||
@Test | ||
fun `toString format check`() { | ||
assertEquals("1:0", AspectRatio.Infinity.toString()) | ||
assertEquals("0:1", AspectRatio.Zero.toString()) | ||
assertEquals("16:9", AspectRatio(16, 9).toString()) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
data/src/test/java/ch/srg/dataProvider/integrationlayer/data/remote/BlockReasonTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ch.srg.dataProvider.integrationlayer.data.remote | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class BlockReasonTest { | ||
@Test | ||
fun `parse value`() { | ||
assertEquals(BlockReason.UNKNOWN, BlockReason.parseValue("")) | ||
assertEquals(BlockReason.UNKNOWN, BlockReason.parseValue("INVALID_REASON")) | ||
|
||
BlockReason.entries.forEach { blockReason -> | ||
assertEquals(blockReason, BlockReason.parseValue(blockReason.name)) | ||
} | ||
|
||
BlockReason.entries.forEach { blockReason -> | ||
assertEquals(BlockReason.UNKNOWN, BlockReason.parseValue(blockReason.name.lowercase())) | ||
} | ||
} | ||
} |
144 changes: 144 additions & 0 deletions
144
data/src/test/java/ch/srg/dataProvider/integrationlayer/data/remote/ChapterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package ch.srg.dataProvider.integrationlayer.data.remote | ||
|
||
import ch.srg.dataProvider.integrationlayer.data.ImageUrl | ||
import java.util.Date | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertNull | ||
import kotlin.test.assertTrue | ||
import kotlin.time.Duration.Companion.minutes | ||
|
||
class ChapterTest { | ||
@Test | ||
fun `find segment with null segment list`() { | ||
val chapter = createChapter(segmentList = null) | ||
|
||
assertNull(chapter.findSegment("urn:rts:video:123456")) | ||
} | ||
|
||
@Test | ||
fun `find segment with empty segment list`() { | ||
val chapter = createChapter(segmentList = emptyList()) | ||
|
||
assertNull(chapter.findSegment("urn:rts:video:123456")) | ||
} | ||
|
||
@Test | ||
fun `find segment with segment list`() { | ||
val segment = createSegment(SEGMENT_URN) | ||
val chapter = createChapter(segmentList = listOf(createSegment("urn:rts:video:987654"), segment)) | ||
|
||
assertNull(chapter.findSegment("urn:rts:video:123456")) | ||
assertEquals(segment, chapter.findSegment(SEGMENT_URN)) | ||
} | ||
|
||
@Test | ||
fun `find 360 resource with null resource list`() { | ||
val chapter = createChapter(resourceList = null) | ||
|
||
assertNull(chapter.find360Resource()) | ||
assertFalse(chapter.is360()) | ||
} | ||
|
||
@Test | ||
fun `find 360 resource with empty resource list`() { | ||
val chapter = createChapter(resourceList = emptyList()) | ||
|
||
assertNull(chapter.find360Resource()) | ||
assertFalse(chapter.is360()) | ||
} | ||
|
||
@Test | ||
fun `find 360 resource without 360 resource in resource list`() { | ||
val chapter = createChapter(resourceList = listOf(createResource(), createResource())) | ||
|
||
assertNull(chapter.find360Resource()) | ||
assertFalse(chapter.is360()) | ||
} | ||
|
||
@Test | ||
fun `find 360 resource with 360 resource in resource list`() { | ||
val resource = createResource(presentation = Presentation.VIDEO_360) | ||
val chapter = createChapter(resourceList = listOf(createResource(), resource)) | ||
|
||
assertEquals(resource, chapter.find360Resource()) | ||
assertTrue(chapter.is360()) | ||
} | ||
|
||
@Test | ||
fun `does have blocked segment with null segment list`() { | ||
val chapter = createChapter(segmentList = null) | ||
|
||
assertFalse(chapter.doesHaveBlockedSegment()) | ||
} | ||
|
||
@Test | ||
fun `does have blocked segment with empty segment list`() { | ||
val chapter = createChapter(segmentList = emptyList()) | ||
|
||
assertFalse(chapter.doesHaveBlockedSegment()) | ||
} | ||
|
||
@Test | ||
fun `does have blocked segment with segment list`() { | ||
val segment = createSegment(SEGMENT_URN, blocked = true) | ||
val chapter = createChapter(segmentList = listOf(createSegment("urn:rts:video:987654"), segment)) | ||
|
||
assertTrue(chapter.doesHaveBlockedSegment()) | ||
} | ||
|
||
private companion object { | ||
private const val SEGMENT_URN = "urn:rts:video:456789" | ||
|
||
private fun createChapter( | ||
segmentList: List<Segment>? = null, | ||
resourceList: List<Resource>? = null, | ||
): Chapter { | ||
return Chapter( | ||
id = "chapter-id", | ||
mediaType = MediaType.VIDEO, | ||
vendor = Vendor.RTS, | ||
urn = "urn:rts:video:123456", | ||
title = "chapter-title", | ||
imageUrl = ImageUrl("https://image.url"), | ||
type = Type.EPISODE, | ||
date = Date(), | ||
duration = 90.minutes.inWholeMilliseconds, | ||
segmentList = segmentList, | ||
resourceList = resourceList, | ||
) | ||
} | ||
|
||
private fun createSegment( | ||
urn: String, | ||
blocked: Boolean = false, | ||
): Segment { | ||
return Segment( | ||
id = "segment-id", | ||
mediaType = MediaType.VIDEO, | ||
vendor = Vendor.RTS, | ||
urn = urn, | ||
title = "segment-title", | ||
markIn = 0L, | ||
markOut = 0L, | ||
type = Type.CLIP, | ||
date = Date(), | ||
duration = 30.minutes.inWholeMilliseconds, | ||
displayable = true, | ||
playableAbroad = true, | ||
imageUrl = ImageUrl("https://image.url"), | ||
blockReason = BlockReason.LEGAL.takeIf { blocked }, | ||
) | ||
} | ||
|
||
private fun createResource(presentation: Presentation = Presentation.DEFAULT): Resource { | ||
return Resource( | ||
url = "https://resource.url", | ||
quality = Quality.HD, | ||
presentation = presentation, | ||
streamingMethod = StreamingMethod.DASH, | ||
) | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
data/src/test/java/ch/srg/dataProvider/integrationlayer/data/remote/ListResultTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package ch.srg.dataProvider.integrationlayer.data.remote | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertNotNull | ||
import kotlin.test.assertTrue | ||
|
||
class ListResultTest { | ||
@Test | ||
fun `list result null data`() { | ||
val listResult = StringListResult(data = null) | ||
|
||
assertEquals(emptyList(), listResult.list) | ||
assertEquals(0, listResult.size) | ||
assertTrue(listResult.isEmpty()) | ||
assertFalse(listResult.contains("")) | ||
assertFalse(listResult.contains("c")) | ||
assertTrue(listResult.containsAll(emptyList())) | ||
assertFalse(listResult.containsAll(listOf("b", "d"))) | ||
assertNotNull(listResult.iterator()) | ||
} | ||
|
||
@Test(expected = IndexOutOfBoundsException::class) | ||
fun `list result null data with get item`() { | ||
val listResult = StringListResult(data = null) | ||
|
||
listResult[0] | ||
} | ||
|
||
@Test | ||
fun `list result empty data`() { | ||
val listResult = StringListResult(data = emptyList()) | ||
|
||
assertEquals(emptyList(), listResult.list) | ||
assertEquals(0, listResult.size) | ||
assertTrue(listResult.isEmpty()) | ||
assertFalse(listResult.contains("")) | ||
assertFalse(listResult.contains("c")) | ||
assertTrue(listResult.containsAll(emptyList())) | ||
assertFalse(listResult.containsAll(listOf("b", "d"))) | ||
assertNotNull(listResult.iterator()) | ||
} | ||
|
||
@Test(expected = IndexOutOfBoundsException::class) | ||
fun `list result empty data with get item`() { | ||
val listResult = StringListResult(data = emptyList()) | ||
|
||
listResult[0] | ||
} | ||
|
||
@Test | ||
fun `list result`() { | ||
val data = listOf("a", "b", "c", "d", "e", "f") | ||
val listResult = StringListResult(data = data) | ||
|
||
assertEquals(data, listResult.list) | ||
assertEquals(data.size, listResult.size) | ||
assertFalse(listResult.isEmpty()) | ||
assertFalse(listResult.contains("")) | ||
assertTrue(listResult.contains("c")) | ||
assertTrue(listResult.containsAll(emptyList())) | ||
assertTrue(listResult.containsAll(listOf("b", "d"))) | ||
assertFalse(listResult.containsAll(listOf("e", "g"))) | ||
assertNotNull(listResult.iterator()) | ||
} | ||
|
||
private class StringListResult( | ||
override val data: List<String>?, | ||
) : ListResult<String>() { | ||
override val next = null | ||
} | ||
} |
Oops, something went wrong.