Skip to content

Commit

Permalink
Migrate the remaining usages of truth to kotest.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulWoitaschek committed Sep 2, 2022
1 parent aee75e3 commit a0b2d38
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 127 deletions.
3 changes: 1 addition & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ dependencies {
implementation(libs.androidxCore)

testImplementation(libs.junit)
testImplementation(libs.truth)
testImplementation(libs.mockk)

implementation(libs.media3.exoplayer)
Expand All @@ -202,7 +201,7 @@ dependencies {

androidTestImplementation(libs.androidTest.espresso)
androidTestImplementation(libs.androidTest.rules)
androidTestImplementation(libs.truth)
androidTestImplementation(libs.koTest.assert)
androidTestImplementation(libs.junit)
androidTestImplementation(libs.compose.ui.test)
debugImplementation(libs.compose.ui.testManifest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import androidx.documentfile.provider.DocumentFile
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.google.common.truth.Truth.assertThat
import io.kotest.matchers.nulls.shouldBeNull
import io.kotest.matchers.shouldBe
import kotlinx.coroutines.runBlocking
import org.junit.Rule
import org.junit.Test
Expand All @@ -27,20 +28,20 @@ class MediaAnalyzerInstrumentationTest {
@Test(timeout = 1000)
fun defectFile_noDuration() {
val duration = durationOfResource(R.raw.defect)
assertThat(duration).isNull()
duration.shouldBeNull()
}

@Test
fun intactFile_correctDuration() {
val duration = durationOfResource(R.raw.intact)
assertThat(duration).isEqualTo(119040)
duration shouldBe 119040
}

@Test(timeout = 1000)
fun subsequentCalls() {
assertThat(durationOfResource(R.raw.intact)).isEqualTo(119040)
assertThat(durationOfResource(R.raw.defect)).isNull()
assertThat(durationOfResource(R.raw.intact2)).isEqualTo(119040)
durationOfResource(R.raw.intact) shouldBe 119040
durationOfResource(R.raw.defect).shouldBeNull()
durationOfResource(R.raw.intact2) shouldBe 119040
}

private fun durationOfResource(@RawRes resource: Int): Long? {
Expand Down
12 changes: 6 additions & 6 deletions app/src/test/kotlin/voice/app/misc/FormatTimeKtTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package voice.app.misc

import com.google.common.truth.Truth.assertThat
import io.kotest.matchers.shouldBe
import org.junit.Test
import voice.common.formatTime
import java.util.concurrent.TimeUnit
Expand All @@ -11,35 +11,35 @@ class FormatTimeKtTest {
fun withSeconds_noDuration_no_hours_multipleDigits() {
val ms = ms(hours = 0, minutes = 59, seconds = 12)
val formatted = formatTime(ms)
assertThat(formatted).isEqualTo("59:12")
formatted shouldBe "59:12"
}

@Test
fun withSeconds_noDuration_no_hours_singleDigit() {
val ms = ms(hours = 0, minutes = 5, seconds = 7)
val formatted = formatTime(ms)
assertThat(formatted).isEqualTo("5:07")
formatted shouldBe "5:07"
}

@Test
fun withSeconds_noDuration_with_hours_multipleDigits() {
val ms = ms(hours = 123, minutes = 59, seconds = 12)
val formatted = formatTime(ms)
assertThat(formatted).isEqualTo("123:59:12")
formatted shouldBe "123:59:12"
}

@Test
fun withDuration_andSeconds() {
val durationMs = ms(hours = 999, minutes = 59, seconds = 12)
val time = ms(0, 12, 13)
val formatted = formatTime(time, durationMs)
assertThat(formatted).isEqualTo("000:12:13")
formatted shouldBe "000:12:13"
}

@Test
fun zero() {
val formatted = formatTime(0)
assertThat(formatted).isEqualTo("0:00")
formatted shouldBe "0:00"
}

private fun ms(hours: Long, minutes: Long, seconds: Long): Long {
Expand Down
9 changes: 5 additions & 4 deletions app/src/test/kotlin/voice/app/mvp/PresenterTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package voice.app.mvp

import com.google.common.truth.Truth.assertThat
import io.kotest.matchers.booleans.shouldBeFalse
import io.kotest.matchers.booleans.shouldBeTrue
import org.junit.Before
import org.junit.Test

Expand All @@ -15,11 +16,11 @@ class PresenterTest {

@Test
fun attached() {
assertThat(presenter.attached).isFalse()
presenter.attached.shouldBeFalse()
presenter.attach(View)
assertThat(presenter.attached).isTrue()
presenter.attached.shouldBeTrue()
presenter.detach()
assertThat(presenter.attached).isFalse()
presenter.attached.shouldBeFalse()
}

private object View
Expand Down
1 change: 0 additions & 1 deletion common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ dependencies {
implementation(libs.viewBinding)
implementation(libs.serialization.json)

testImplementation(libs.truth)
testImplementation(libs.junit)
testImplementation(libs.androidX.test.core)
testImplementation(libs.androidX.test.junit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package voice.common.comparator

import android.net.Uri
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import io.kotest.matchers.collections.shouldContainExactly
import io.kotest.matchers.shouldBe
import org.junit.After
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -67,7 +68,7 @@ class NaturalOrderComparatorTest {
"folder10/1.mp3",
)
val sorted = expected.sortedWith(NaturalOrderComparator.stringComparator)
assertThat(sorted).isEqualTo(expected)
sorted shouldBe expected
}

@Test
Expand Down Expand Up @@ -105,19 +106,17 @@ class NaturalOrderComparatorTest {
.build()
}

assertThat(uris.sortedWith(NaturalOrderComparator.uriComparator))
.containsExactlyElementsIn(uris)
.inOrder()
uris.sortedWith(NaturalOrderComparator.uriComparator)
.shouldContainExactly(uris)
}

@Test
fun uriComparatorFiles() {
val expected = testFiles()
val uris = expected.map { Uri.fromFile(it) }

assertThat(uris.sortedWith(NaturalOrderComparator.uriComparator))
.containsExactlyElementsIn(uris)
.inOrder()
uris.sortedWith(NaturalOrderComparator.uriComparator)
.shouldContainExactly(uris)
}

@After
Expand Down
1 change: 0 additions & 1 deletion data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ dependencies {
testImplementation(libs.androidX.test.runner)
testImplementation(libs.junit)
testImplementation(libs.robolectric)
testImplementation(libs.truth)
testImplementation(libs.prefs.inMemory)
testImplementation(libs.koTest.assert)
testImplementation(libs.coroutines.test)
Expand Down
8 changes: 4 additions & 4 deletions data/src/test/kotlin/voice/data/BookComparatorTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package voice.data

import com.google.common.truth.Truth.assertThat
import io.kotest.matchers.collections.shouldContainExactly
import org.junit.Test

class BookComparatorTest {
Expand All @@ -15,18 +15,18 @@ class BookComparatorTest {
@Test
fun byLastPlayed() {
val sorted = books.sortedWith(BookComparator.ByLastPlayed)
assertThat(sorted).containsExactly(b4, b5, b3, b1, b2).inOrder()
sorted.shouldContainExactly(b4, b5, b3, b1, b2)
}

@Test
fun byName() {
val sorted = books.sortedWith(BookComparator.ByName)
assertThat(sorted).containsExactly(b1, b2, b3, b5, b4).inOrder()
sorted.shouldContainExactly(b1, b2, b3, b5, b4)
}

@Test
fun byDateAdded() {
val sorted = books.sortedWith(BookComparator.ByDateAdded)
assertThat(sorted).containsExactly(b4, b5, b1, b2, b3).inOrder()
sorted.shouldContainExactly(b4, b5, b1, b2, b3)
}
}
52 changes: 0 additions & 52 deletions data/src/test/kotlin/voice/data/BookSubject.kt

This file was deleted.

25 changes: 14 additions & 11 deletions data/src/test/kotlin/voice/data/BookTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package voice.data

import io.kotest.matchers.ints.shouldBeExactly
import io.kotest.matchers.longs.shouldBeExactly
import io.kotest.matchers.nulls.shouldBeNull
import io.kotest.matchers.shouldBe
import org.junit.Test

class BookTest {
Expand Down Expand Up @@ -36,7 +39,7 @@ class BookTest {
chapters = chapters,
currentChapter = chapters.first().id,
)
book.assertThat().positionIs(0)
book.position shouldBeExactly 0L
}

@Test
Expand All @@ -47,7 +50,7 @@ class BookTest {
chapters = chapters,
currentChapter = chapters.first().id,
)
book.assertThat().positionIs(23)
book.position shouldBeExactly 23
}

@Test
Expand All @@ -63,7 +66,7 @@ class BookTest {
),
currentChapter = lastChapterId,
)
book.assertThat().positionIs(123 + 234 + 345)
book.position shouldBeExactly 123 + 234 + 345
}

@Test
Expand All @@ -79,7 +82,7 @@ class BookTest {
),
currentChapter = targetChapter,
)
book.assertThat().positionIs(123 + 234 + 23)
book.position shouldBeExactly 123 + 234 + 23
}

@Test
Expand All @@ -93,7 +96,7 @@ class BookTest {
),
)

book.assertThat().durationIs(123 + 234 + 345 + 456)
book.duration shouldBeExactly 123 + 234 + 345 + 456
}

@Test
Expand All @@ -105,7 +108,7 @@ class BookTest {
chapters = listOf(ch1, ch2, ch3),
currentChapter = ch2.id,
)
book.assertThat().currentChapterIs(ch2)
book.currentChapter shouldBe ch2
}

@Test
Expand All @@ -118,7 +121,7 @@ class BookTest {
currentChapter = ch2.id,
)

book.assertThat().currentChapterIndexIs(1)
book.content.currentChapterIndex shouldBeExactly 1
}

@Test
Expand All @@ -131,7 +134,7 @@ class BookTest {
currentChapter = ch2.id,
)

book.assertThat().nextChapterIs(ch3)
book.nextChapter shouldBe ch3
}

@Test
Expand All @@ -144,7 +147,7 @@ class BookTest {
currentChapter = ch3.id,
)

book.assertThat().nextChapterIs(null)
book.nextChapter.shouldBeNull()
}

@Test
Expand All @@ -156,7 +159,7 @@ class BookTest {
chapters = listOf(ch1, ch2, ch3),
currentChapter = ch2.id,
)
book.assertThat().previousChapterIs(ch1)
book.previousChapter shouldBe ch1
}

@Test
Expand All @@ -168,7 +171,7 @@ class BookTest {
chapters = listOf(ch1, ch2, ch3),
currentChapter = ch1.id,
)
book.assertThat().previousChapterIs(null)
book.previousChapter.shouldBeNull()
}

@Suppress("SameParameterValue")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package voice.data.repo.internals

import com.google.common.truth.Truth.assertThat
import io.kotest.matchers.shouldBe
import org.junit.Test
import voice.data.MarkData
import voice.data.legacy.LegacyBookType
Expand Down Expand Up @@ -58,6 +58,6 @@ class ConvertersTest {
val converters = Converters()
val serialized: S = converters.serialize(value)
val deSerialized: D = converters.deSerialize(serialized)
assertThat(deSerialized).isEqualTo(value)
deSerialized shouldBe value
}
}
Loading

0 comments on commit a0b2d38

Please sign in to comment.