Skip to content

Commit f02b689

Browse files
author
Maxime NATUREL
committed
Adding unit tests for mapper
1 parent b23520e commit f02b689

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/mapper/MyDeviceLastSeenInfoEntityMapper.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import javax.inject.Inject
2222

2323
internal class MyDeviceLastSeenInfoEntityMapper @Inject constructor() {
2424

25-
// TODO add unit tests
2625
fun map(entity: MyDeviceLastSeenInfoEntity): DeviceInfo {
2726
return DeviceInfo(
2827
deviceId = entity.deviceId,

matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/crypto/store/db/mapper/MyDeviceLastSeenInfoEntityMapperTest.kt

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,63 @@ private const val A_DEVICE_ID = "device-id"
2525
private const val AN_IP_ADDRESS = "ip-address"
2626
private const val A_TIMESTAMP = 123L
2727
private const val A_DISPLAY_NAME = "display-name"
28+
private const val A_USER_AGENT = "user-agent"
2829

2930
class MyDeviceLastSeenInfoEntityMapperTest {
3031

3132
private val myDeviceLastSeenInfoEntityMapper = MyDeviceLastSeenInfoEntityMapper()
3233

3334
@Test
3435
fun `given an entity when mapping to model then all fields are correctly mapped`() {
36+
// Given
3537
val entity = MyDeviceLastSeenInfoEntity(
3638
deviceId = A_DEVICE_ID,
3739
lastSeenIp = AN_IP_ADDRESS,
3840
lastSeenTs = A_TIMESTAMP,
39-
displayName = A_DISPLAY_NAME
41+
displayName = A_DISPLAY_NAME,
42+
lastSeenUserAgent = A_USER_AGENT,
4043
)
4144
val expectedDeviceInfo = DeviceInfo(
4245
deviceId = A_DEVICE_ID,
4346
lastSeenIp = AN_IP_ADDRESS,
4447
lastSeenTs = A_TIMESTAMP,
45-
displayName = A_DISPLAY_NAME
48+
displayName = A_DISPLAY_NAME,
49+
unstableLastSeenUserAgent = A_USER_AGENT,
4650
)
4751

52+
// When
4853
val deviceInfo = myDeviceLastSeenInfoEntityMapper.map(entity)
4954

55+
// Then
5056
deviceInfo shouldBeEqualTo expectedDeviceInfo
5157
}
58+
59+
@Test
60+
fun `given a device info when mapping to entity then all fields are correctly mapped`() {
61+
// Given
62+
val deviceInfo = DeviceInfo(
63+
deviceId = A_DEVICE_ID,
64+
lastSeenIp = AN_IP_ADDRESS,
65+
lastSeenTs = A_TIMESTAMP,
66+
displayName = A_DISPLAY_NAME,
67+
unstableLastSeenUserAgent = A_USER_AGENT,
68+
)
69+
val expectedEntity = MyDeviceLastSeenInfoEntity(
70+
deviceId = A_DEVICE_ID,
71+
lastSeenIp = AN_IP_ADDRESS,
72+
lastSeenTs = A_TIMESTAMP,
73+
displayName = A_DISPLAY_NAME,
74+
lastSeenUserAgent = A_USER_AGENT
75+
)
76+
77+
// When
78+
val entity = myDeviceLastSeenInfoEntityMapper.map(deviceInfo)
79+
80+
// Then
81+
entity.deviceId shouldBeEqualTo expectedEntity.deviceId
82+
entity.lastSeenIp shouldBeEqualTo expectedEntity.lastSeenIp
83+
entity.lastSeenTs shouldBeEqualTo expectedEntity.lastSeenTs
84+
entity.displayName shouldBeEqualTo expectedEntity.displayName
85+
entity.lastSeenUserAgent shouldBeEqualTo expectedEntity.lastSeenUserAgent
86+
}
5287
}

0 commit comments

Comments
 (0)