mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-12-03 15:08:05 +00:00
Kotlin-ize ReleaseVersionUtil, merge with NewVersionManager
This commit is contained in:
@@ -2,8 +2,9 @@ package org.schabi.newpipe
|
||||
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.schabi.newpipe.util.ReleaseVersionUtil.coerceUpdateCheckExpiry
|
||||
import org.schabi.newpipe.util.ReleaseVersionUtil.isLastUpdateCheckExpired
|
||||
import java.time.Instant
|
||||
import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
@@ -11,18 +12,11 @@ import kotlin.math.abs
|
||||
|
||||
class NewVersionManagerTest {
|
||||
|
||||
private lateinit var manager: NewVersionManager
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
manager = NewVersionManager()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Expiry is reached`() {
|
||||
val oneHourEarlier = Instant.now().atZone(ZoneId.of("GMT")).minusHours(1)
|
||||
|
||||
val expired = manager.isExpired(oneHourEarlier.toEpochSecond())
|
||||
val expired = isLastUpdateCheckExpired(oneHourEarlier.toEpochSecond())
|
||||
|
||||
assertTrue(expired)
|
||||
}
|
||||
@@ -31,7 +25,7 @@ class NewVersionManagerTest {
|
||||
fun `Expiry is not reached`() {
|
||||
val oneHourLater = Instant.now().atZone(ZoneId.of("GMT")).plusHours(1)
|
||||
|
||||
val expired = manager.isExpired(oneHourLater.toEpochSecond())
|
||||
val expired = isLastUpdateCheckExpired(oneHourLater.toEpochSecond())
|
||||
|
||||
assertFalse(expired)
|
||||
}
|
||||
@@ -47,7 +41,7 @@ class NewVersionManagerTest {
|
||||
fun `Expiry must be returned as is because it is inside the acceptable range of 6-72 hours`() {
|
||||
val sixHoursLater = Instant.now().atZone(ZoneId.of("GMT")).plusHours(6)
|
||||
|
||||
val coerced = manager.coerceExpiry(DateTimeFormatter.RFC_1123_DATE_TIME.format(sixHoursLater))
|
||||
val coerced = coerceUpdateCheckExpiry(DateTimeFormatter.RFC_1123_DATE_TIME.format(sixHoursLater))
|
||||
|
||||
assertNearlyEqual(sixHoursLater.toEpochSecond(), coerced)
|
||||
}
|
||||
@@ -56,7 +50,7 @@ class NewVersionManagerTest {
|
||||
fun `Expiry must be increased to 6 hours if below`() {
|
||||
val tooLow = Instant.now().atZone(ZoneId.of("GMT")).plusHours(5)
|
||||
|
||||
val coerced = manager.coerceExpiry(DateTimeFormatter.RFC_1123_DATE_TIME.format(tooLow))
|
||||
val coerced = coerceUpdateCheckExpiry(DateTimeFormatter.RFC_1123_DATE_TIME.format(tooLow))
|
||||
|
||||
assertNearlyEqual(tooLow.plusHours(1).toEpochSecond(), coerced)
|
||||
}
|
||||
@@ -65,7 +59,7 @@ class NewVersionManagerTest {
|
||||
fun `Expiry must be decreased to 72 hours if above`() {
|
||||
val tooHigh = Instant.now().atZone(ZoneId.of("GMT")).plusHours(73)
|
||||
|
||||
val coerced = manager.coerceExpiry(DateTimeFormatter.RFC_1123_DATE_TIME.format(tooHigh))
|
||||
val coerced = coerceUpdateCheckExpiry(DateTimeFormatter.RFC_1123_DATE_TIME.format(tooHigh))
|
||||
|
||||
assertNearlyEqual(tooHigh.minusHours(1).toEpochSecond(), coerced)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user