Commit 2616e7e6 authored by Joey's avatar Joey

tests: use proper junit methods

* Remove google truth
* Use org.junit.Assert
Signed-off-by: Joey's avatarJoey <bevilacquajoey@gmail.com>
parent 88930bde
Pipeline #56631426 passed with stages
in 15 minutes and 25 seconds
......@@ -11,13 +11,13 @@ package it.diab.viewmodels.glucose
import android.content.Context
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.test.core.app.ApplicationProvider
import com.google.common.truth.Truth.assertThat
import it.diab.core.data.AppDatabase
import it.diab.core.data.repositories.GlucoseRepository
import it.diab.core.data.repositories.InsulinRepository
import it.diab.core.util.extensions.insulin
import it.diab.util.extensions.get
import it.diab.util.extensions.getWeekDay
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
......@@ -52,8 +52,7 @@ class GlucoseListViewModelTest {
fun getInsulin() {
val test = TEST_DATA[0]
assertThat(viewModel.getInsulin(test.uid))
.isEqualTo(test)
assertEquals(test, viewModel.getInsulin(test.uid))
}
@Test
......@@ -65,14 +64,10 @@ class GlucoseListViewModelTest {
val format = SimpleDateFormat("yyyy-MM-dd")
assertThat(viewModel.runSetHeader(a, format))
.isEqualTo(TODAY)
assertThat(viewModel.runSetHeader(b, format))
.isEqualTo(YESTERDAY)
assertThat(viewModel.runSetHeader(c, format))
.isEqualTo(LAST_X.format(c.getWeekDay()))
assertThat(viewModel.runSetHeader(d, format))
.isEqualTo(format.format(d))
assertEquals(TODAY, viewModel.runSetHeader(a, format))
assertEquals(YESTERDAY, viewModel.runSetHeader(b, format))
assertEquals(LAST_X.format(c.getWeekDay()), viewModel.runSetHeader(c, format))
assertEquals(format.format(d), viewModel.runSetHeader(d, format))
}
companion object {
......
......@@ -11,12 +11,12 @@ package it.diab.viewmodels.glucose
import android.content.Context
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.test.core.app.ApplicationProvider
import com.google.common.truth.Truth.assertThat
import it.diab.core.data.AppDatabase
import it.diab.core.data.entities.TimeFrame
import it.diab.core.data.repositories.GlucoseRepository
import it.diab.core.util.extensions.glucose
import it.diab.core.data.entities.TimeFrame
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
......@@ -49,7 +49,6 @@ class OverviewViewModelTest {
fun getAverageLastWeek() = runBlocking {
val pair = viewModel.runGetDataSets(glucoseList.asList())
assertThat(pair.second[testTimeFrame.toInt()].y)
.isEqualTo(glucoseValues.average().toFloat())
assertEquals(glucoseValues.average().toFloat(), pair.second[testTimeFrame.toInt()].y)
}
}
\ No newline at end of file
......@@ -10,6 +10,8 @@ package it.diab.util.extensions
import it.diab.core.util.DateUtils
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import java.util.Calendar
import java.util.Date
......@@ -20,7 +22,7 @@ class DateExtTest {
fun get() {
val now = System.currentTimeMillis()
val diff = 2
assertEquals(Date(now)[diff].time, now + (DateUtils.DAY * diff))
assertEquals(now + (DateUtils.DAY * diff), Date(now)[diff].time)
}
@Test
......@@ -33,9 +35,9 @@ class DateExtTest {
this[Calendar.DAY_OF_YEAR] += 3
}.time
assertEquals(a.isToday(), true)
assertEquals(b.isToday(), false)
assertEquals(c.isToday(), false)
assertTrue(a.isToday())
assertFalse(b.isToday())
assertFalse(c.isToday())
}
@Test
......@@ -45,7 +47,7 @@ class DateExtTest {
set(Calendar.MINUTE, 30)
}
assertEquals(calendar.time.getAsMinutes(), 10 * 60f + 30)
assertEquals(10 * 60f + 30, calendar.time.getAsMinutes())
}
@Test
......@@ -60,10 +62,10 @@ class DateExtTest {
set(Calendar.DAY_OF_YEAR, 3)
}
assertEquals(a.time.diff(b.time), -2)
assertEquals(-2, a.time.diff(b.time))
b[Calendar.YEAR] -= 1
b[Calendar.DAY_OF_YEAR] -= 8
assertEquals(a.time.diff(b.time), 371)
assertEquals(371, a.time.diff(b.time))
}
}
\ No newline at end of file
......@@ -10,13 +10,13 @@ package it.diab.core.data
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import com.google.common.truth.Truth.assertThat
import it.diab.core.data.dao.GlucoseDao
import it.diab.core.data.dao.InsulinDao
import it.diab.core.data.entities.Glucose
import it.diab.core.data.entities.TimeFrame
import it.diab.core.util.extensions.glucose
import it.diab.core.util.extensions.insulin
import junit.framework.Assert.assertEquals
import org.junit.Before
import org.junit.Test
......@@ -44,7 +44,7 @@ class AppDatabaseTest {
glucoseDao.insert(item)
val test = glucoseDao.getById(1)[0]
assertThat(item).isEqualTo(test)
assertEquals(test, item)
}
@Test
......@@ -57,7 +57,7 @@ class AppDatabaseTest {
}.also { insulinDao.insert(it) }
val test = insulinDao.getById(1)[0]
assertThat(item).isEqualTo(test)
assertEquals(test, item)
}
@Test
......@@ -91,8 +91,8 @@ class AppDatabaseTest {
val test1 = insulinDao.getById(insulinId0)[0]
val test2 = insulinDao.getById(insulinId1)[0]
assertThat(insulin.uid).isEqualTo(test1.uid)
assertThat(basal.uid).isEqualTo(test2.uid)
assertEquals(test1.uid, insulin.uid)
assertEquals(test2.uid, basal.uid)
}
}
}
......@@ -9,11 +9,12 @@
package it.diab.core.data.repositories
import androidx.test.platform.app.InstrumentationRegistry
import com.google.common.truth.Truth.assertThat
import it.diab.core.data.AppDatabase
import it.diab.core.util.DateUtils
import it.diab.core.util.extensions.glucose
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Before
import org.junit.Test
import java.util.Date
......@@ -53,8 +54,8 @@ class GlucoseRepositoryTest {
data.forEach { repository.insert(it) }
val list = repository.getInDateRange(start, end)
assertThat(list.size).isEqualTo(daysRange + 1)
assertThat(list[1].value).isEqualTo(baseValue * 2)
assertEquals(daysRange + 1, list.size)
assertEquals(baseValue * 2, list[1].value)
}
@Test
......@@ -66,8 +67,8 @@ class GlucoseRepositoryTest {
repository.insert(glucose)
repository.getById(glucose.uid).run {
assertThat(uid).isEqualTo(glucose.uid)
assertThat(this).isEqualTo(glucose)
assertEquals(glucose.uid, uid)
assertEquals(glucose, this)
}
}
......@@ -79,9 +80,9 @@ class GlucoseRepositoryTest {
}
repository.insert(glucose)
assertThat(repository.getById(glucose.uid).uid).isEqualTo(glucose.uid)
assertEquals(glucose.uid, repository.getById(glucose.uid).uid)
repository.delete(glucose)
assertThat(repository.getById(glucose.uid)).isNotEqualTo(glucose.uid)
assertNotEquals(glucose.uid, repository.getById(glucose.uid).uid)
}
}
\ No newline at end of file
......@@ -9,10 +9,12 @@
package it.diab.core.data.repositories
import androidx.test.platform.app.InstrumentationRegistry
import com.google.common.truth.Truth.assertThat
import it.diab.core.data.AppDatabase
import it.diab.core.util.extensions.hba1c
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertNotNull
import org.junit.Before
import org.junit.Test
......@@ -38,8 +40,8 @@ class Hba1cRepositoryTest {
repository.insert(item)
val inRepo = repository.getById(item.uid)
assertThat(inRepo).isEqualTo(item)
assertThat(inRepo?.uid ?: -1).isEqualTo(item.uid)
assertEquals(item, inRepo)
assertEquals(item.uid, inRepo?.uid ?: -1)
}
@Test
......@@ -50,10 +52,10 @@ class Hba1cRepositoryTest {
}
repository.insert(item)
assertThat(repository.getById(item.uid)).isNotNull()
assertNotNull(repository.getById(item.uid))
repository.delete(item)
assertThat(repository.getById(item.uid)).isNotEqualTo(item.uid)
assertNotEquals(item.uid, repository.getById(item.uid))
}
private fun Hba1cRepository.getById(uid: Long) = getAllItems().firstOrNull { it.uid == uid }
......
......@@ -9,10 +9,11 @@
package it.diab.core.data.repositories
import androidx.test.platform.app.InstrumentationRegistry
import com.google.common.truth.Truth.assertThat
import it.diab.core.data.AppDatabase
import it.diab.core.util.extensions.insulin
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Before
import org.junit.Test
......@@ -42,7 +43,7 @@ class InsulinRepositoryTest {
data.forEach { repository.insert(it) }
assertThat(repository.getBasals().size).isEqualTo(data.size / 2)
assertEquals(data.size / 2, repository.getBasals().size)
}
@Test
......@@ -54,8 +55,8 @@ class InsulinRepositoryTest {
repository.insert(insulin)
repository.getById(insulin.uid).run {
assertThat(uid).isEqualTo(insulin.uid)
assertThat(this).isEqualTo(insulin)
assertEquals(insulin.uid, uid)
assertEquals(insulin, this)
}
}
......@@ -67,9 +68,9 @@ class InsulinRepositoryTest {
}
repository.insert(insulin)
assertThat(repository.getById(insulin.uid).uid).isEqualTo(insulin.uid)
assertEquals(insulin.uid, repository.getById(insulin.uid).uid)
repository.delete(insulin)
assertThat(repository.getById(insulin.uid).uid).isNotEqualTo(insulin.uid)
assertNotEquals(insulin.uid, repository.getById(insulin.uid).uid)
}
}
\ No newline at end of file
......@@ -18,16 +18,16 @@ class DateConverterTest {
@Test
fun convertToDate() {
val now = System.currentTimeMillis()
assertEquals(converter.toDate(now).time, now)
assertEquals(now, converter.toDate(now).time)
assertEquals(converter.toDate(null).time, 0)
assertEquals(0, converter.toDate(null).time)
}
@Test
fun convertToLong() {
val now = Date()
assertEquals(converter.toLong(now), now.time)
assertEquals(now.time, converter.toLong(now))
assertEquals(converter.toLong(null), 0)
assertEquals(0, converter.toLong(null))
}
}
\ No newline at end of file
......@@ -17,18 +17,13 @@ class TimeFrameConverterTest {
@Test
fun convertToInt() {
val tf = TimeFrame.LATE_MORNING
assertEquals(converter.toInt(tf), 1)
assertEquals(converter.toInt(null), TimeFrame.EXTRA.toInt())
assertEquals(1, converter.toInt(TimeFrame.LATE_MORNING))
assertEquals(TimeFrame.EXTRA.toInt(), converter.toInt(null))
}
@Test
fun convertToTimeFrame() {
val tf = 1
assertEquals(converter.toTimeFrame(tf), TimeFrame.LATE_MORNING)
assertEquals(converter.toTimeFrame(null), TimeFrame.EXTRA)
assertEquals(TimeFrame.LATE_MORNING, converter.toTimeFrame(1))
assertEquals(TimeFrame.EXTRA, converter.toTimeFrame(null))
}
}
\ No newline at end of file
......@@ -9,6 +9,7 @@
package it.diab.core.data.entities
import it.diab.core.util.extensions.glucose
import org.junit.Assert.assertTrue
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
......@@ -21,13 +22,13 @@ class GlucoseTest {
@Test
fun defaults() {
glucose { uid = 12 }.run {
assertEquals(value, 0)
assertEquals(insulinId0, -1)
assertEquals(insulinValue0, 0f)
assertEquals(insulinId1, -1)
assertEquals(insulinValue1, 0f)
assertEquals(eatLevel, Glucose.MEDIUM)
assertEquals(timeFrame, TimeFrame.EXTRA)
assertEquals(0, value)
assertEquals(-1, insulinId0)
assertEquals(0f, insulinValue0)
assertEquals(-1, insulinId1)
assertEquals(0f, insulinValue1)
assertEquals(Glucose.MEDIUM, eatLevel)
assertEquals(TimeFrame.EXTRA, timeFrame)
}
}
......@@ -45,7 +46,7 @@ class GlucoseTest {
date = Date(0)
}
assertEquals(a, b)
assertEquals(a.hashCode(), b.hashCode())
assertTrue(a == b)
assertTrue(a.hashCode() == b.hashCode())
}
}
\ No newline at end of file
......@@ -9,8 +9,9 @@
package it.diab.core.data.entities
import it.diab.core.util.extensions.hba1c
import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertTrue
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
......@@ -45,11 +46,11 @@ class Hba1cTest {
}
assertTrue(a == b)
assertTrue(a != c)
assertTrue(b != c)
assertFalse(a == c)
assertFalse(b == c)
assertTrue(a.hashCode() == b.hashCode())
assertTrue(a.hashCode() != c.hashCode())
assertTrue(a.hashCode() != c.hashCode())
assertFalse(a.hashCode() == c.hashCode())
assertFalse(a.hashCode() == c.hashCode())
}
}
\ No newline at end of file
......@@ -10,6 +10,8 @@ package it.diab.core.data.entities
import it.diab.core.util.extensions.insulin
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
......@@ -20,10 +22,10 @@ class InsulinTest {
@Test
fun defaults() {
insulin { uid = 12 }.run {
assertEquals(name, "")
assertEquals(timeFrame, TimeFrame.EXTRA)
assertEquals(isBasal, false)
assertEquals(hasHalfUnits, false)
assertEquals("", name)
assertEquals(TimeFrame.EXTRA, timeFrame)
assertFalse(isBasal)
assertFalse(hasHalfUnits)
}
}
......@@ -32,14 +34,14 @@ class InsulinTest {
val insulin = insulin { timeFrame = TimeFrame.MORNING }
insulin.setTimeFrame(5)
assertEquals(insulin.timeFrame, TimeFrame.NIGHT)
assertEquals(TimeFrame.NIGHT, insulin.timeFrame)
}
@Test
fun getDisplayedString() {
val insulin = insulin { name = "test" }
assertEquals(insulin.getDisplayedString(10.54f), "test 10.5")
assertEquals("test 10.5", insulin.getDisplayedString(10.54f))
}
@Test
......@@ -54,7 +56,7 @@ class InsulinTest {
name = "test"
}
assertEquals(a, b)
assertEquals(a.hashCode(), b.hashCode())
assertTrue(a == b)
assertTrue(a.hashCode() == b.hashCode())
}
}
\ No newline at end of file
......@@ -24,13 +24,13 @@ class DateExtTest {
val calendar = Calendar.getInstance()
calendar[Calendar.HOUR_OF_DAY] = 8
assertEquals(calendar.time.asTimeFrame(), TimeFrame.MORNING)
assertEquals(TimeFrame.MORNING, calendar.time.asTimeFrame())
calendar[Calendar.HOUR_OF_DAY] = 18
assertEquals(calendar.time.asTimeFrame(), TimeFrame.AFTERNOON)
assertEquals(TimeFrame.AFTERNOON, calendar.time.asTimeFrame())
calendar[Calendar.HOUR_OF_DAY] = 0
assertEquals(calendar.time.asTimeFrame(), TimeFrame.NIGHT)
assertEquals(TimeFrame.NIGHT, calendar.time.asTimeFrame())
}
@Test
......@@ -42,16 +42,16 @@ class DateExtTest {
set(Calendar.MINUTE, 30)
}
assertEquals(calendar.time.format("yyyy-MM-dd"), "1971-01-01")
assertEquals("1971-01-01", calendar.time.format("yyyy-MM-dd"))
assertEquals(calendar.time.format("HH:mm"), "10:30")
assertEquals("10:30", calendar.time.format("HH:mm"))
}
@Test
fun getCalendar() {
val calendar = Calendar.getInstance()
val date = calendar.time
assertEquals(date.getCalendar(), calendar)
assertEquals(calendar, date.getCalendar())
}
@Test
......@@ -60,6 +60,6 @@ class DateExtTest {
set(Calendar.HOUR_OF_DAY, 10)
}
assertEquals(calendar.time.getHour(), 10)
assertEquals(10, calendar.time.getHour())
}
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ class SingletonHolderTest {
val a = TestData.getInstance("abc")
val b = TestData.getInstance("def")
assertEquals(a.toString(), b.toString())
assertEquals(a, b)
}
private class TestData private constructor(
......@@ -30,6 +30,12 @@ class SingletonHolderTest {
override fun toString() = uid
override fun equals(other: Any?) = other != null &&
other is TestData &&
other.toString() == toString()
override fun hashCode() = toString().hashCode()
companion object : SingletonHolder<TestData, String> ({ TestData(it) })
}
}
\ No newline at end of file
......@@ -12,6 +12,5 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.1'
androidTestImplementation 'com.google.truth:truth:0.43'
testImplementation 'junit:junit:4.12'
}
\ No newline at end of file
......@@ -29,9 +29,7 @@ android {
dependencies {
implementation project(':core')
implementation("androidx.work:work-runtime-ktx:2.0.1") {
exclude group: 'com.google.guava', module: 'listenablefuture'
}
implementation("androidx.work:work-runtime-ktx:2.0.1")
}
// Testing dependencies
......
......@@ -11,7 +11,6 @@ package it.diab.glucose.viewmodels
import android.content.Context
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.test.core.app.ApplicationProvider
import com.google.common.truth.Truth.assertThat
import it.diab.core.data.AppDatabase
import it.diab.core.data.entities.Glucose
import it.diab.core.data.entities.TimeFrame
......@@ -22,6 +21,9 @@ import it.diab.core.util.extensions.glucose
import it.diab.core.util.extensions.insulin
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
......@@ -60,7 +62,7 @@ class EditorViewModelTest {
val context = ApplicationProvider.getApplicationContext<Context>()
db = AppDatabase.getInstance(context)
viewModel = it.diab.glucose.viewmodels.EditorViewModel(
viewModel = EditorViewModel(
GlucoseRepository.getInstance(context),
InsulinRepository.getInstance(context)
)
......@@ -74,8 +76,8 @@ class EditorViewModelTest {
fun setGlucose() = runBlocking {
viewModel.runSetGlucose(testGlucose.uid)
viewModel.glucose.run {
assertThat(uid).isEqualTo(testGlucose.uid)
assertThat(this).isEqualTo(testGlucose)
assertEquals(testGlucose.uid, uid)
assertEquals(testGlucose, this)
}
}
......@@ -97,15 +99,15 @@ class EditorViewModelTest {
delay(500)
val finalSize = db.glucose().getInDateRange(0, System.currentTimeMillis()).size
assertThat(finalSize).isGreaterThan(initialSize)
assertTrue(finalSize > initialSize)
}
@Test
fun getInsulin() = runBlocking {
viewModel.runPrepare(this, pluginManager)
viewModel.getInsulin(testInsulin.uid).run {
assertThat(uid).isEqualTo(testInsulin.uid)
assertThat(this).isEqualTo(testInsulin)
assertEquals(testInsulin.uid, uid)
assertEquals(testInsulin, this)
}
}
......@@ -114,7 +116,7 @@ class EditorViewModelTest {
viewModel.runPrepare(this, pluginManager)
viewModel.glucose.timeFrame = testBasal.timeFrame
assertThat(viewModel.hasPotentialBasal()).isTrue()
assertTrue(viewModel.hasPotentialBasal())
}
@Test
......@@ -122,8 +124,7 @@ class EditorViewModelTest {
viewModel.runPrepare(this, pluginManager)
viewModel.glucose.timeFrame = testInsulin.timeFrame
assertThat(viewModel.getInsulinByTimeFrame().timeFrame)
.isEqualTo(viewModel.glucose.timeFrame)
assertEquals(viewModel.glucose.timeFrame, viewModel.getInsulinByTimeFrame().timeFrame)
}
@Test
......@@ -132,8 +133,8 @@ class EditorViewModelTest {
viewModel.runApplySuggestion(test, testInsulin)
viewModel.glucose.run {
assertThat(insulinValue0).isEqualTo(test)
assertThat(insulinId0).isEqualTo(testInsulin.uid)
assertEquals(test, insulinValue0)
assertEquals(testInsulin.uid, insulinId0)
}
}
......@@ -145,33 +146,33 @@ class EditorViewModelTest {
val d = 1 shl 2
viewModel.setError(a)
assertThat(viewModel.hasError(a)).isFalse()
assertThat(viewModel.hasErrors()).isFalse()
assertFalse(viewModel.hasError(a))
assertFalse(viewModel.hasErrors())
viewModel.setError(b)
assertThat(viewModel.hasError(b)).isTrue()
assertThat(viewModel.hasError(c)).isFalse()
assertTrue(viewModel.hasError(b))
assertFalse(viewModel.hasError(c))
viewModel.setError(c)
assertThat(viewModel.hasError(b)).isTrue()
assertThat(viewModel.hasError(c)).isTrue()
assertThat(viewModel.hasError(d)).isFalse()
assertTrue(viewModel.hasError(b))
assertTrue(viewModel.hasError(c))
assertFalse(viewModel.hasError(d))
viewModel.clearError(b)
assertThat(viewModel.hasError(b)).isFalse()
assertThat(viewModel.hasError(c)).isTrue()
assertThat(viewModel.hasError(d)).isFalse()
assertFalse(viewModel.hasError(b))
assertTrue(viewModel.hasError(c))
assertFalse(viewModel.hasError(d))
assertThat(viewModel.hasErrors()).isTrue()
assertTrue(viewModel.hasErrors())
viewModel.setError(d)
assertThat(viewModel.hasError(b)).isFalse()
assertThat(viewModel.hasError(c)).isTrue()
assertThat(viewModel.hasError(d)).isTrue()
assertFalse(viewModel.hasError(b))
assertTrue(viewModel.hasError(c))
assertTrue(viewModel.</