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 com.google.common.truth.Truth
|
||||||
import gq.kirmanak.mealient.extensions.RoomTypeConverters
|
|
||||||
import kotlinx.datetime.LocalDate
|
import kotlinx.datetime.LocalDate
|
||||||
import kotlinx.datetime.LocalDateTime
|
import kotlinx.datetime.LocalDateTime
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@@ -11,27 +10,27 @@ class RoomTypeConvertersTest {
|
|||||||
fun `when localDateTimeToTimestamp then correctly converts`() {
|
fun `when localDateTimeToTimestamp then correctly converts`() {
|
||||||
val input = LocalDateTime.parse("2021-11-13T15:56:33")
|
val input = LocalDateTime.parse("2021-11-13T15:56:33")
|
||||||
val actual = RoomTypeConverters.localDateTimeToTimestamp(input)
|
val actual = RoomTypeConverters.localDateTimeToTimestamp(input)
|
||||||
assertThat(actual).isEqualTo(1636818993000)
|
Truth.assertThat(actual).isEqualTo(1636818993000)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when timestampToLocalDateTime then correctly converts`() {
|
fun `when timestampToLocalDateTime then correctly converts`() {
|
||||||
val expected = LocalDateTime.parse("2021-11-13T15:58:38")
|
val expected = LocalDateTime.parse("2021-11-13T15:58:38")
|
||||||
val actual = RoomTypeConverters.timestampToLocalDateTime(1636819118000)
|
val actual = RoomTypeConverters.timestampToLocalDateTime(1636819118000)
|
||||||
assertThat(actual).isEqualTo(expected)
|
Truth.assertThat(actual).isEqualTo(expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when localDateToTimeStamp then correctly converts`() {
|
fun `when localDateToTimeStamp then correctly converts`() {
|
||||||
val input = LocalDate.parse("2021-11-13")
|
val input = LocalDate.parse("2021-11-13")
|
||||||
val actual = RoomTypeConverters.localDateToTimeStamp(input)
|
val actual = RoomTypeConverters.localDateToTimeStamp(input)
|
||||||
assertThat(actual).isEqualTo(1636761600000)
|
Truth.assertThat(actual).isEqualTo(1636761600000)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when timestampToLocalDate then correctly converts`() {
|
fun `when timestampToLocalDate then correctly converts`() {
|
||||||
val expected = LocalDate.parse("2021-11-13")
|
val expected = LocalDate.parse("2021-11-13")
|
||||||
val actual = RoomTypeConverters.timestampToLocalDate(1636761600000)
|
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.Rule
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.robolectric.annotation.Config
|
import org.robolectric.annotation.Config
|
||||||
import timber.log.Timber
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
@Config(application = HiltTestApplication::class, manifest = Config.NONE)
|
@Config(application = HiltTestApplication::class, manifest = Config.NONE)
|
||||||
abstract class HiltRobolectricTest {
|
abstract class HiltRobolectricTest {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun setupTimber() {
|
fun setupTimber() = plantPrintLn()
|
||||||
Timber.plant(object : Timber.Tree() {
|
|
||||||
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
|
|
||||||
println(message)
|
|
||||||
t?.printStackTrace()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@get:Rule
|
@get:Rule
|
||||||
|
|||||||
@@ -2,9 +2,18 @@ package gq.kirmanak.mealient.test
|
|||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import org.junit.BeforeClass
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.robolectric.annotation.Config
|
import org.robolectric.annotation.Config
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
@Config(application = Application::class, manifest = Config.NONE)
|
@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.MediaType.Companion.toMediaType
|
||||||
import okhttp3.ResponseBody.Companion.toResponseBody
|
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