Rewrites SessionTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-09-23 20:56:06 -07:00
parent c95cdc1c9b
commit 5668377307

View file

@ -1,32 +1,44 @@
package info.nightscout.plugins.sync.tidepool.comm package info.nightscout.plugins.sync.tidepool.comm
import com.google.common.truth.Truth.assertThat
import info.nightscout.plugins.sync.tidepool.messages.AuthReplyMessage import info.nightscout.plugins.sync.tidepool.messages.AuthReplyMessage
import info.nightscout.plugins.sync.tidepool.messages.DatasetReplyMessage import info.nightscout.plugins.sync.tidepool.messages.DatasetReplyMessage
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class SessionTest { class SessionTest {
private val session = Session("", "", null)
@Test @Test
fun populateBody() { fun emptySession() {
val session = Session("", "", null) assertThat(session.authReply).isNull()
Assertions.assertNull(session.authReply) assertThat(session.datasetReply).isNull()
}
// test authReply @Test
fun authReply() {
val authReplyMessage = AuthReplyMessage() val authReplyMessage = AuthReplyMessage()
session.populateBody(authReplyMessage) session.populateBody(authReplyMessage)
Assertions.assertEquals(authReplyMessage, session.authReply)
// test datasetReply assertThat(session.authReply).isEqualTo(authReplyMessage)
}
@Test
fun datasetReply() {
val datasetReplyMessage = DatasetReplyMessage() val datasetReplyMessage = DatasetReplyMessage()
Assertions.assertNull(session.datasetReply)
session.populateBody(datasetReplyMessage)
Assertions.assertEquals(datasetReplyMessage, session.datasetReply)
// test datasetReply as array session.populateBody(datasetReplyMessage)
val list: List<DatasetReplyMessage> = listOf(datasetReplyMessage)
session.datasetReply = null assertThat(session.datasetReply).isEqualTo(datasetReplyMessage)
session.populateBody(list) }
Assertions.assertEquals(datasetReplyMessage, session.datasetReply)
@Test
fun datasetReply_asList() {
val datasetReplyMessage = DatasetReplyMessage()
session.populateBody(listOf(datasetReplyMessage))
assertThat(session.datasetReply).isEqualTo(datasetReplyMessage)
} }
} }