Reorganize test code
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package gq.kirmanak.mealient.data.impl
|
||||
package gq.kirmanak.mealient.extensions
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import gq.kirmanak.mealient.extensions.RoomTypeConverters
|
||||
import com.google.common.truth.Truth
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
import org.junit.Test
|
||||
@@ -11,27 +10,27 @@ class RoomTypeConvertersTest {
|
||||
fun `when localDateTimeToTimestamp then correctly converts`() {
|
||||
val input = LocalDateTime.parse("2021-11-13T15:56:33")
|
||||
val actual = RoomTypeConverters.localDateTimeToTimestamp(input)
|
||||
assertThat(actual).isEqualTo(1636818993000)
|
||||
Truth.assertThat(actual).isEqualTo(1636818993000)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when timestampToLocalDateTime then correctly converts`() {
|
||||
val expected = LocalDateTime.parse("2021-11-13T15:58:38")
|
||||
val actual = RoomTypeConverters.timestampToLocalDateTime(1636819118000)
|
||||
assertThat(actual).isEqualTo(expected)
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when localDateToTimeStamp then correctly converts`() {
|
||||
val input = LocalDate.parse("2021-11-13")
|
||||
val actual = RoomTypeConverters.localDateToTimeStamp(input)
|
||||
assertThat(actual).isEqualTo(1636761600000)
|
||||
Truth.assertThat(actual).isEqualTo(1636761600000)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when timestampToLocalDate then correctly converts`() {
|
||||
val expected = LocalDate.parse("2021-11-13")
|
||||
val actual = RoomTypeConverters.timestampToLocalDate(1636761600000)
|
||||
assertThat(actual).isEqualTo(expected)
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
}
|
||||
@@ -8,22 +8,16 @@ import org.junit.BeforeClass
|
||||
import org.junit.Rule
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.annotation.Config
|
||||
import timber.log.Timber
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@Config(application = HiltTestApplication::class, manifest = Config.NONE)
|
||||
abstract class HiltRobolectricTest {
|
||||
|
||||
companion object {
|
||||
|
||||
@BeforeClass
|
||||
@JvmStatic
|
||||
fun setupTimber() {
|
||||
Timber.plant(object : Timber.Tree() {
|
||||
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
|
||||
println(message)
|
||||
t?.printStackTrace()
|
||||
}
|
||||
})
|
||||
}
|
||||
fun setupTimber() = plantPrintLn()
|
||||
}
|
||||
|
||||
@get:Rule
|
||||
|
||||
@@ -2,9 +2,18 @@ package gq.kirmanak.mealient.test
|
||||
|
||||
import android.app.Application
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@Config(application = Application::class, manifest = Config.NONE)
|
||||
abstract class RobolectricTest
|
||||
abstract class RobolectricTest {
|
||||
|
||||
companion object {
|
||||
|
||||
@BeforeClass
|
||||
@JvmStatic
|
||||
fun setupTimber() = plantPrintLn()
|
||||
}
|
||||
}
|
||||
@@ -2,5 +2,15 @@ package gq.kirmanak.mealient.test
|
||||
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||
import timber.log.Timber
|
||||
|
||||
fun String.toJsonResponseBody() = toResponseBody("application/json".toMediaType())
|
||||
fun String.toJsonResponseBody() = toResponseBody("application/json".toMediaType())
|
||||
|
||||
fun plantPrintLn() {
|
||||
Timber.plant(object : Timber.Tree() {
|
||||
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
|
||||
println(message)
|
||||
t?.printStackTrace()
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user