@@ -21,8 +21,10 @@ import org.schabi.newpipe.extractor.ServiceList
2121import org.schabi.newpipe.extractor.channel.ChannelInfo
2222import org.schabi.newpipe.extractor.stream.StreamType
2323import java.io.IOException
24- import java.time.OffsetDateTime
25- import kotlin.streams.toList
24+ import java.time.Instant
25+ import java.time.LocalDate
26+ import java.time.Month
27+ import java.time.ZoneOffset
2628
2729class FeedDAOTest {
2830 private lateinit var db: AppDatabase
@@ -32,13 +34,13 @@ class FeedDAOTest {
3234
3335 private val serviceId = ServiceList .YouTube .serviceId
3436
35- private val stream1 = StreamEntity (1 , serviceId, " https://youtube.com/watch?v=1" , " stream 1" , StreamType .VIDEO_STREAM , 1000 , " channel-1" , " https://youtube.com/channel/1" , " https://i.ytimg.com/vi/1/hqdefault.jpg" , 100 , " 2023-01-01" , OffsetDateTime .parse(" 2023-01-01T00:00:00Z" ))
36- private val stream2 = StreamEntity (2 , serviceId, " https://youtube.com/watch?v=2" , " stream 2" , StreamType .VIDEO_STREAM , 1000 , " channel-1" , " https://youtube.com/channel/1" , " https://i.ytimg.com/vi/1/hqdefault.jpg" , 100 , " 2023-01-02" , OffsetDateTime .parse(" 2023-01-02T00:00:00Z" ))
37- private val stream3 = StreamEntity (3 , serviceId, " https://youtube.com/watch?v=3" , " stream 3" , StreamType .LIVE_STREAM , 1000 , " channel-1" , " https://youtube.com/channel/1" , " https://i.ytimg.com/vi/1/hqdefault.jpg" , 100 , " 2023-01-03" , OffsetDateTime .parse(" 2023-01-03T00:00:00Z" ))
38- private val stream4 = StreamEntity (4 , serviceId, " https://youtube.com/watch?v=4" , " stream 4" , StreamType .VIDEO_STREAM , 1000 , " channel-2" , " https://youtube.com/channel/2" , " https://i.ytimg.com/vi/1/hqdefault.jpg" , 100 , " 2023-08-10" , OffsetDateTime .parse(" 2023-08-10T00:00:00Z" ))
39- private val stream5 = StreamEntity (5 , serviceId, " https://youtube.com/watch?v=5" , " stream 5" , StreamType .VIDEO_STREAM , 1000 , " channel-2" , " https://youtube.com/channel/2" , " https://i.ytimg.com/vi/1/hqdefault.jpg" , 100 , " 2023-08-20" , OffsetDateTime .parse(" 2023-08-20T00:00:00Z" ))
40- private val stream6 = StreamEntity (6 , serviceId, " https://youtube.com/watch?v=6" , " stream 6" , StreamType .VIDEO_STREAM , 1000 , " channel-3" , " https://youtube.com/channel/3" , " https://i.ytimg.com/vi/1/hqdefault.jpg" , 100 , " 2023-09-01" , OffsetDateTime .parse(" 2023-09-01T00:00:00Z" ))
41- private val stream7 = StreamEntity (7 , serviceId, " https://youtube.com/watch?v=7" , " stream 7" , StreamType .VIDEO_STREAM , 1000 , " channel-4" , " https://youtube.com/channel/4" , " https://i.ytimg.com/vi/1/hqdefault.jpg" , 100 , " 2023-08-10" , OffsetDateTime .parse(" 2023-08-10T00:00:00Z" ))
37+ private val stream1 = StreamEntity (1 , serviceId, " https://youtube.com/watch?v=1" , " stream 1" , StreamType .VIDEO_STREAM , 1000 , " channel-1" , " https://youtube.com/channel/1" , " https://i.ytimg.com/vi/1/hqdefault.jpg" , 100 , " 2023-01-01" , Instant .parse(" 2023-01-01T00:00:00Z" ))
38+ private val stream2 = StreamEntity (2 , serviceId, " https://youtube.com/watch?v=2" , " stream 2" , StreamType .VIDEO_STREAM , 1000 , " channel-1" , " https://youtube.com/channel/1" , " https://i.ytimg.com/vi/1/hqdefault.jpg" , 100 , " 2023-01-02" , Instant .parse(" 2023-01-02T00:00:00Z" ))
39+ private val stream3 = StreamEntity (3 , serviceId, " https://youtube.com/watch?v=3" , " stream 3" , StreamType .LIVE_STREAM , 1000 , " channel-1" , " https://youtube.com/channel/1" , " https://i.ytimg.com/vi/1/hqdefault.jpg" , 100 , " 2023-01-03" , Instant .parse(" 2023-01-03T00:00:00Z" ))
40+ private val stream4 = StreamEntity (4 , serviceId, " https://youtube.com/watch?v=4" , " stream 4" , StreamType .VIDEO_STREAM , 1000 , " channel-2" , " https://youtube.com/channel/2" , " https://i.ytimg.com/vi/1/hqdefault.jpg" , 100 , " 2023-08-10" , Instant .parse(" 2023-08-10T00:00:00Z" ))
41+ private val stream5 = StreamEntity (5 , serviceId, " https://youtube.com/watch?v=5" , " stream 5" , StreamType .VIDEO_STREAM , 1000 , " channel-2" , " https://youtube.com/channel/2" , " https://i.ytimg.com/vi/1/hqdefault.jpg" , 100 , " 2023-08-20" , Instant .parse(" 2023-08-20T00:00:00Z" ))
42+ private val stream6 = StreamEntity (6 , serviceId, " https://youtube.com/watch?v=6" , " stream 6" , StreamType .VIDEO_STREAM , 1000 , " channel-3" , " https://youtube.com/channel/3" , " https://i.ytimg.com/vi/1/hqdefault.jpg" , 100 , " 2023-09-01" , Instant .parse(" 2023-09-01T00:00:00Z" ))
43+ private val stream7 = StreamEntity (7 , serviceId, " https://youtube.com/watch?v=7" , " stream 7" , StreamType .VIDEO_STREAM , 1000 , " channel-4" , " https://youtube.com/channel/4" , " https://i.ytimg.com/vi/1/hqdefault.jpg" , 100 , " 2023-08-10" , Instant .parse(" 2023-08-10T00:00:00Z" ))
4244
4345 private val allStreams = listOf (
4446 stream1, stream2, stream3, stream4, stream5, stream6, stream7
@@ -63,7 +65,7 @@ class FeedDAOTest {
6365
6466 @Test
6567 fun testUnlinkStreamsOlderThan_KeepOne () {
66- setupUnlinkDelete(" 2023-08-15T00:00:00Z " )
68+ setupUnlinkDelete(LocalDate .of( 2023 , Month . AUGUST , 15 ) )
6769 val streams = feedDAO.getStreams(
6870 FeedGroupEntity .GROUP_ALL_ID , includePlayed = true , includePartiallyPlayed = true , null
6971 )
@@ -74,7 +76,7 @@ class FeedDAOTest {
7476
7577 @Test
7678 fun testUnlinkStreamsOlderThan_KeepMultiple () {
77- setupUnlinkDelete(" 2023-08-01T00:00:00Z " )
79+ setupUnlinkDelete(LocalDate .of( 2023 , Month . AUGUST , 1 ) )
7880 val streams = feedDAO.getStreams(
7981 FeedGroupEntity .GROUP_ALL_ID , includePlayed = true , includePartiallyPlayed = true , null
8082 )
@@ -94,10 +96,10 @@ class FeedDAOTest {
9496 )
9597 }
9698
97- private fun setupUnlinkDelete (time : String ) {
99+ private fun setupUnlinkDelete (localDate : LocalDate ) {
98100 clearAndFillTables()
99101 Single .fromCallable {
100- feedDAO.unlinkStreamsOlderThan(OffsetDateTime .parse(time ))
102+ feedDAO.unlinkStreamsOlderThan(localDate.atStartOfDay( ZoneOffset . UTC ).toInstant( ))
101103 }.blockingSubscribe()
102104 Single .fromCallable {
103105 streamDAO.deleteOrphans()
0 commit comments