Adding unit tests for mapper

This commit is contained in:
Maxime NATUREL 2022-08-31 14:12:16 +02:00
parent 40d716d099
commit 295ae55142
2 changed files with 52 additions and 1 deletions

View File

@ -20,7 +20,6 @@ import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
import org.matrix.android.sdk.internal.crypto.store.db.model.MyDeviceLastSeenInfoEntity import org.matrix.android.sdk.internal.crypto.store.db.model.MyDeviceLastSeenInfoEntity
import javax.inject.Inject import javax.inject.Inject
// TODO add unit tests
internal class MyDeviceLastSeenInfoEntityMapper @Inject constructor() { internal class MyDeviceLastSeenInfoEntityMapper @Inject constructor() {
fun map(entity: MyDeviceLastSeenInfoEntity): DeviceInfo { fun map(entity: MyDeviceLastSeenInfoEntity): DeviceInfo {

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.crypto.store.db.mapper
import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
import org.matrix.android.sdk.internal.crypto.store.db.model.MyDeviceLastSeenInfoEntity
private const val A_DEVICE_ID = "device-id"
private const val AN_IP_ADDRESS = "ip-address"
private const val A_TIMESTAMP = 123L
private const val A_DISPLAY_NAME = "display-name"
class MyDeviceLastSeenInfoEntityMapperTest {
private val myDeviceLastSeenInfoEntityMapper = MyDeviceLastSeenInfoEntityMapper()
@Test
fun `given an entity when mapping to model then all fields are correctly mapped`() {
val entity = MyDeviceLastSeenInfoEntity(
deviceId = A_DEVICE_ID,
lastSeenIp = AN_IP_ADDRESS,
lastSeenTs = A_TIMESTAMP,
displayName = A_DISPLAY_NAME
)
val expectedDeviceInfo = DeviceInfo(
deviceId = A_DEVICE_ID,
lastSeenIp = AN_IP_ADDRESS,
lastSeenTs = A_TIMESTAMP,
displayName = A_DISPLAY_NAME
)
val deviceInfo = myDeviceLastSeenInfoEntityMapper.map(entity)
deviceInfo shouldBeEqualTo expectedDeviceInfo
}
}