parent
b64a5d4715
commit
2cbcf8bd50
1 changed files with 10 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.plugins.general.smsCommunicator
|
package info.nightscout.plugins.general.smsCommunicator
|
||||||
|
|
||||||
import app.aaps.shared.tests.TestBase
|
import app.aaps.shared.tests.TestBase
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.interfaces.Constants
|
import info.nightscout.interfaces.Constants
|
||||||
|
@ -12,7 +13,6 @@ import info.nightscout.plugins.general.smsCommunicator.otp.OneTimePasswordValida
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
import org.junit.jupiter.api.Assertions
|
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
|
@ -61,26 +61,26 @@ class AuthRequestTest : TestBase() {
|
||||||
|
|
||||||
// Check if SMS requesting code is sent
|
// Check if SMS requesting code is sent
|
||||||
var authRequest = AuthRequest(injector, requester, "Request text", "ABC", action)
|
var authRequest = AuthRequest(injector, requester, "Request text", "ABC", action)
|
||||||
Assertions.assertEquals(sentSms!!.phoneNumber, "aNumber")
|
assertThat(sentSms!!.phoneNumber).isEqualTo("aNumber")
|
||||||
Assertions.assertEquals(sentSms!!.text, "Request text")
|
assertThat(sentSms!!.text).isEqualTo("Request text")
|
||||||
|
|
||||||
// wrong reply
|
// wrong reply
|
||||||
actionCalled = false
|
actionCalled = false
|
||||||
authRequest.action("EFG")
|
authRequest.action("EFG")
|
||||||
Assertions.assertEquals(sentSms!!.phoneNumber, "aNumber")
|
assertThat(sentSms!!.phoneNumber).isEqualTo("aNumber")
|
||||||
Assertions.assertEquals(sentSms!!.text, "Wrong code. Command cancelled.")
|
assertThat(sentSms!!.text).isEqualTo("Wrong code. Command cancelled.")
|
||||||
Assertions.assertFalse(actionCalled)
|
assertThat(actionCalled).isFalse()
|
||||||
|
|
||||||
// correct reply
|
// correct reply
|
||||||
authRequest = AuthRequest(injector, requester, "Request text", "ABC", action)
|
authRequest = AuthRequest(injector, requester, "Request text", "ABC", action)
|
||||||
actionCalled = false
|
actionCalled = false
|
||||||
`when`(otp.checkOTP(anyObject())).thenReturn(OneTimePasswordValidationResult.OK)
|
`when`(otp.checkOTP(anyObject())).thenReturn(OneTimePasswordValidationResult.OK)
|
||||||
authRequest.action("ABC")
|
authRequest.action("ABC")
|
||||||
Assertions.assertTrue(actionCalled)
|
assertThat(actionCalled).isTrue()
|
||||||
// second time action should not be called
|
// second time action should not be called
|
||||||
actionCalled = false
|
actionCalled = false
|
||||||
authRequest.action("ABC")
|
authRequest.action("ABC")
|
||||||
Assertions.assertFalse(actionCalled)
|
assertThat(actionCalled).isFalse()
|
||||||
|
|
||||||
// test timed out message
|
// test timed out message
|
||||||
val now: Long = 10000
|
val now: Long = 10000
|
||||||
|
@ -89,6 +89,6 @@ class AuthRequestTest : TestBase() {
|
||||||
actionCalled = false
|
actionCalled = false
|
||||||
`when`(dateUtil.now()).thenReturn(now + T.mins(Constants.SMS_CONFIRM_TIMEOUT).msecs() + 1)
|
`when`(dateUtil.now()).thenReturn(now + T.mins(Constants.SMS_CONFIRM_TIMEOUT).msecs() + 1)
|
||||||
authRequest.action("ABC")
|
authRequest.action("ABC")
|
||||||
Assertions.assertFalse(actionCalled)
|
assertThat(actionCalled).isFalse()
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue