AndroidAPS/app/src/test/java/info/TestBase.kt

41 lines
1.8 KiB
Kotlin
Raw Normal View History

2020-03-01 16:18:19 +01:00
package info
2020-02-28 22:51:12 +01:00
2020-03-09 00:28:51 +01:00
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.data.Profile
2020-03-09 23:24:46 +01:00
import info.nightscout.androidaps.data.ProfileStore
2020-03-09 00:28:51 +01:00
import org.json.JSONObject
2020-02-28 22:51:12 +01:00
import org.junit.Rule
import org.mockito.Mockito
import org.mockito.junit.MockitoJUnit
import org.mockito.junit.MockitoRule
open class TestBase {
2020-03-09 00:28:51 +01:00
val validProfileJSON = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"},{\"time\":\"2:00\",\"value\":\"110\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
val validProfile: Profile = Profile(JSONObject(validProfileJSON), Constants.MGDL)
2020-03-09 23:24:46 +01:00
val TESTPROFILENAME = "someProfile"
fun getValidProfileStore(): ProfileStore {
val json = JSONObject()
val store = JSONObject()
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
json.put("defaultProfile", TESTPROFILENAME)
json.put("store", store)
return ProfileStore(json)
}
2020-03-09 00:28:51 +01:00
2020-02-28 22:51:12 +01:00
// Add a JUnit rule that will setup the @Mock annotated vars and log.
// Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method.
@get:Rule
val mockitoRule: MockitoRule = MockitoJUnit.rule()
// Workaround for Kotlin nullability.
// https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791
// https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin
fun <T> anyObject(): T {
Mockito.any<T>()
return uninitialized()
}
@Suppress("Unchecked_Cast")
fun <T> uninitialized(): T = null as T
}