Repo created

This commit is contained in:
Fr4nz D13trich 2025-11-24 18:55:42 +01:00
parent a629de6271
commit 3cef7c5092
2161 changed files with 246605 additions and 2 deletions

View file

@ -0,0 +1,7 @@
plugins {
id(ThunderbirdPlugins.Library.jvm)
}
dependencies {
implementation(libs.assertk)
}

View file

@ -0,0 +1,19 @@
package app.k9mail.core.testing
import kotlin.time.Duration
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
class TestClock(
private var currentTime: Instant = Clock.System.now(),
) : Clock {
override fun now(): Instant = currentTime
fun changeTimeTo(time: Instant) {
currentTime = time
}
fun advanceTimeBy(duration: Duration) {
currentTime += duration
}
}

View file

@ -0,0 +1,13 @@
package assertk.assertions
import assertk.Assert
import assertk.assertions.support.expected
import assertk.assertions.support.show
fun <T> Assert<List<T>>.containsNoDuplicates() = given { actual ->
val seen: MutableSet<T> = mutableSetOf()
val duplicates = actual.filter { !seen.add(it) }
if (duplicates.isNotEmpty()) {
expected("to contain no duplicates but found: ${show(duplicates)}")
}
}

View file

@ -0,0 +1,39 @@
package app.k9mail.core.testing
import assertk.assertThat
import assertk.assertions.isEqualTo
import kotlin.test.Test
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.datetime.Instant
internal class TestClockTest {
@Test
fun `should return the current time`() {
val testClock = TestClock(Instant.DISTANT_PAST)
val currentTime = testClock.now()
assertThat(currentTime).isEqualTo(Instant.DISTANT_PAST)
}
@Test
fun `should return the changed time`() {
val testClock = TestClock(Instant.DISTANT_PAST)
testClock.changeTimeTo(Instant.DISTANT_FUTURE)
val currentTime = testClock.now()
assertThat(currentTime).isEqualTo(Instant.DISTANT_FUTURE)
}
@Test
fun `should advance time by duration`() {
val testClock = TestClock(Instant.DISTANT_PAST)
testClock.advanceTimeBy(1L.milliseconds)
val currentTime = testClock.now()
assertThat(currentTime).isEqualTo(Instant.DISTANT_PAST + 1L.milliseconds)
}
}

View file

@ -0,0 +1,28 @@
package assertk.assertions
import assertk.assertThat
import kotlin.test.Test
class ListExtensionsKtTest {
@Test
fun `containsNoDuplicates() should succeed with no duplicates`() {
val list = listOf("a", "b", "c")
assertThat(list).containsNoDuplicates()
}
@Test
fun `containsNoDuplicates() should fail with duplicates`() {
val list = listOf("a", "b", "c", "a", "a")
assertThat {
assertThat(list).containsNoDuplicates()
}.isFailure()
.hasMessage(
"""
expected to contain no duplicates but found: <["a", "a"]>
""".trimIndent(),
)
}
}