Skip to content

Commit f4e9d00

Browse files
Fix tests
1 parent 5e8eb71 commit f4e9d00

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

app/src/androidTest/java/org/schabi/newpipe/database/FeedDAOTest.kt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import org.schabi.newpipe.extractor.ServiceList
2121
import org.schabi.newpipe.extractor.channel.ChannelInfo
2222
import org.schabi.newpipe.extractor.stream.StreamType
2323
import 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

2729
class 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()

app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import org.schabi.newpipe.database.history.model.SearchHistoryEntry
1212
import org.schabi.newpipe.testUtil.TestDatabase
1313
import org.schabi.newpipe.testUtil.TrampolineSchedulerRule
1414
import java.time.LocalDateTime
15-
import java.time.OffsetDateTime
1615
import java.time.ZoneOffset
1716

1817
class HistoryRecordManagerTest {
@@ -163,7 +162,8 @@ class HistoryRecordManagerTest {
163162
}
164163

165164
companion object {
166-
private val time = OffsetDateTime.of(LocalDateTime.of(2000, 1, 1, 1, 1), ZoneOffset.UTC)
165+
private val time = LocalDateTime.of(2000, 1, 1, 1, 1)
166+
.toInstant(ZoneOffset.UTC)
167167

168168
private val RELATED_SEARCHES_ENTRIES = listOf(
169169
SearchHistoryEntry(time.minusSeconds(7), 2, "AC"),

app/src/main/java/org/schabi/newpipe/util/Localization.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ public static void initPrettyTime(@NonNull final PrettyTime time) {
366366
prettyTime.removeUnit(Decade.class);
367367
}
368368

369+
static void resetPrettyTime() {
370+
prettyTime = null;
371+
}
372+
369373
public static PrettyTime resolvePrettyTime() {
370374
return new PrettyTime(getAppLocale());
371375
}

app/src/test/java/org/schabi/newpipe/util/LocalizationTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import java.util.Locale
1212
class LocalizationTest {
1313
@Test(expected = NullPointerException::class)
1414
fun `formatRelativeTime() must fail without initializing pretty time`() {
15-
val instant = Instant.now()
16-
Localization.formatRelativeTime(instant)
15+
Localization.resetPrettyTime()
16+
Localization.formatRelativeTime(Instant.now())
1717
}
1818

1919
@Test

0 commit comments

Comments
 (0)