parent
83cee8558d
commit
7fa8b87f6d
|
@ -6,7 +6,6 @@ import app.aaps.plugins.automation.elements.InputLocationMode
|
|||
import com.google.common.truth.Truth.assertThat
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.Mockito.`when`
|
||||
|
@ -24,10 +23,10 @@ class TriggerLocationTest : TriggerTestBase() {
|
|||
t.distance.setValue(2.0)
|
||||
t.modeSelected.value = InputLocationMode.Mode.INSIDE
|
||||
val t1 = t.duplicate() as TriggerLocation
|
||||
Assertions.assertEquals(213.0, t1.latitude.value, 0.01)
|
||||
Assertions.assertEquals(212.0, t1.longitude.value, 0.01)
|
||||
Assertions.assertEquals(2.0, t1.distance.value, 0.01)
|
||||
Assertions.assertEquals(InputLocationMode.Mode.INSIDE, t1.modeSelected.value)
|
||||
assertThat(t1.latitude.value).isWithin(0.01).of(213.0)
|
||||
assertThat(t1.longitude.value).isWithin(0.01).of(212.0)
|
||||
assertThat(t1.distance.value).isWithin(0.01).of(2.0)
|
||||
assertThat(t1.modeSelected.value).isEqualTo(InputLocationMode.Mode.INSIDE)
|
||||
}
|
||||
|
||||
@Test fun shouldRunTest() {
|
||||
|
@ -37,12 +36,12 @@ class TriggerLocationTest : TriggerTestBase() {
|
|||
t.distance.setValue(2.0)
|
||||
// t.modeSelected.setValue(InputLocationMode.Mode.OUTSIDE);
|
||||
`when`(locationDataContainer.lastLocation).thenReturn(null)
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isFalse()
|
||||
`when`(locationDataContainer.lastLocation).thenReturn(mockedLocation())
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
t = TriggerLocation(injector)
|
||||
t.distance.setValue(-500.0)
|
||||
Assertions.assertFalse(t.shouldRun())
|
||||
assertThat(t.shouldRun()).isFalse()
|
||||
|
||||
//Test of GOING_IN - last mode should be OUTSIDE, and current mode should be INSIDE
|
||||
t = TriggerLocation(injector)
|
||||
|
@ -51,9 +50,9 @@ class TriggerLocationTest : TriggerTestBase() {
|
|||
`when`(locationDataContainer.lastLocation).thenReturn(null)
|
||||
`when`(locationDataContainer.lastLocation).thenReturn(mockedLocationOut())
|
||||
t.modeSelected.value = InputLocationMode.Mode.GOING_IN
|
||||
Assertions.assertEquals(t.lastMode, InputLocationMode.Mode.OUTSIDE)
|
||||
Assertions.assertEquals(t.currentMode(5.0), InputLocationMode.Mode.INSIDE)
|
||||
Assertions.assertTrue(t.shouldRun())
|
||||
assertThat(InputLocationMode.Mode.OUTSIDE).isEqualTo(t.lastMode)
|
||||
assertThat(InputLocationMode.Mode.INSIDE).isEqualTo(t.currentMode(5.0))
|
||||
assertThat(t.shouldRun()).isTrue()
|
||||
|
||||
//Test of GOING_OUT - last mode should be INSIDE, and current mode should be OUTSIDE
|
||||
// Currently unavailable due to problems with Location mocking
|
||||
|
@ -67,7 +66,7 @@ class TriggerLocationTest : TriggerTestBase() {
|
|||
t.distance.setValue(2.0)
|
||||
t.modeSelected.value = InputLocationMode.Mode.OUTSIDE
|
||||
// t.modeSelected = t.modeSelected.value
|
||||
Assertions.assertEquals(locationJson, t.toJSON())
|
||||
assertThat(t.toJSON()).isEqualTo(locationJson)
|
||||
}
|
||||
|
||||
@Test @Throws(JSONException::class) fun fromJSONTest() {
|
||||
|
@ -77,18 +76,18 @@ class TriggerLocationTest : TriggerTestBase() {
|
|||
t.distance.setValue(2.0)
|
||||
t.modeSelected.value = InputLocationMode.Mode.INSIDE
|
||||
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerLocation
|
||||
Assertions.assertEquals(t.latitude.value, t2.latitude.value, 0.01)
|
||||
Assertions.assertEquals(t.longitude.value, t2.longitude.value, 0.01)
|
||||
Assertions.assertEquals(t.distance.value, t2.distance.value, 0.01)
|
||||
Assertions.assertEquals(t.modeSelected.value, t2.modeSelected.value)
|
||||
assertThat(t2.latitude.value).isWithin(0.01).of(t.latitude.value)
|
||||
assertThat(t2.longitude.value).isWithin(0.01).of(t.longitude.value)
|
||||
assertThat(t2.distance.value).isWithin(0.01).of(t.distance.value)
|
||||
assertThat(t2.modeSelected.value).isEqualTo(t.modeSelected.value)
|
||||
}
|
||||
|
||||
@Test fun friendlyNameTest() {
|
||||
Assertions.assertEquals(R.string.location, TriggerLocation(injector).friendlyName())
|
||||
assertThat(TriggerLocation(injector).friendlyName()).isEqualTo(R.string.location)
|
||||
}
|
||||
|
||||
@Test fun friendlyDescriptionTest() {
|
||||
Assertions.assertEquals(null, TriggerLocation(injector).friendlyDescription()) //not mocked }
|
||||
assertThat(TriggerLocation(injector).friendlyDescription()).isNull() //not mocked }
|
||||
}
|
||||
|
||||
@Test fun iconTest() {
|
||||
|
@ -110,4 +109,4 @@ class TriggerLocationTest : TriggerTestBase() {
|
|||
newLocation.accuracy = 1f
|
||||
return newLocation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue