summaryrefslogtreecommitdiff
path: root/core/testing/src
diff options
context:
space:
mode:
authortest@dangofactory.cos <you@example.com>2026-08-20 16:57:18 +0000
committertest@dangofactory.cos <you@example.com>2026-08-20 16:57:18 +0000
commit50ce5d5e6cd0d720ff437d35eace545816848428 (patch)
treeb59af206a36265cf081945e434900b32b0c43edd /core/testing/src
downloadmonocles_mail-50ce5d5e6cd0d720ff437d35eace545816848428.tar.gz
monocles_mail-50ce5d5e6cd0d720ff437d35eace545816848428.tar.bz2
monocles_mail-50ce5d5e6cd0d720ff437d35eace545816848428.zip
Inital
Diffstat (limited to 'core/testing/src')
-rw-r--r--core/testing/src/main/kotlin/app/k9mail/core/testing/TestClock.kt19
-rw-r--r--core/testing/src/main/kotlin/assertk/assertions/ListExtensions.kt13
-rw-r--r--core/testing/src/test/kotlin/app/k9mail/core/testing/TestClockTest.kt39
-rw-r--r--core/testing/src/test/kotlin/assertk/assertions/ListExtensionsKtTest.kt28
4 files changed, 99 insertions, 0 deletions
diff --git a/core/testing/src/main/kotlin/app/k9mail/core/testing/TestClock.kt b/core/testing/src/main/kotlin/app/k9mail/core/testing/TestClock.kt
new file mode 100644
index 0000000..508b2c4
--- /dev/null
+++ b/core/testing/src/main/kotlin/app/k9mail/core/testing/TestClock.kt
@@ -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
+ }
+}
diff --git a/core/testing/src/main/kotlin/assertk/assertions/ListExtensions.kt b/core/testing/src/main/kotlin/assertk/assertions/ListExtensions.kt
new file mode 100644
index 0000000..2ab42b2
--- /dev/null
+++ b/core/testing/src/main/kotlin/assertk/assertions/ListExtensions.kt
@@ -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)}")
+ }
+}
diff --git a/core/testing/src/test/kotlin/app/k9mail/core/testing/TestClockTest.kt b/core/testing/src/test/kotlin/app/k9mail/core/testing/TestClockTest.kt
new file mode 100644
index 0000000..980133f
--- /dev/null
+++ b/core/testing/src/test/kotlin/app/k9mail/core/testing/TestClockTest.kt
@@ -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)
+ }
+}
diff --git a/core/testing/src/test/kotlin/assertk/assertions/ListExtensionsKtTest.kt b/core/testing/src/test/kotlin/assertk/assertions/ListExtensionsKtTest.kt
new file mode 100644
index 0000000..6978dae
--- /dev/null
+++ b/core/testing/src/test/kotlin/assertk/assertions/ListExtensionsKtTest.kt
@@ -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(),
+ )
+ }
+}