I have two objects remote model and domain model
Remote model
data class InstanceRemoteModel (
val id: String,
val containers: List<Container>,
val operations: List<Operation>
)
data class ContainerRemoteModel (
val id: String,
val capacity: Long
)
data class OperationRemoteModel (
val id: String,
val weight: Long,
val containerId: String
)
Domain Model
data class Instance (
val id: String,
val containers: Map<String, Container>,
val operations: Map<String, Operation>
)
data class Container (
val id: String,
val capacity: Long
val total_weight: Long
)
data class Operation (
val id: String,
val weight: Long,
val container: Container
)
And then I have a mapper that map objects from remote model to domain model. Here I will concentrate on mapping the containers. Note that a Container
object in the domain model have different properties than ContainerRemoteModel
. The same thing is done with the operations.
object Mapper {
fun toDomainModel(remoteInstance: InstanceRemoteModel): Instance {
val containers : Map<String, Container> = mapContainers(remoteInstance)
val operations : Map<String, Operation> = mapOperations(remoteInstance)
return Instance(remoteInstance.id,containers,operations)
}
private fun mapContainers(remoteInstance: InstanceRemoteModel) : Map<String, Container> {
//do some computations
val containers : List<Container> = remoteInstance.containers.map { cont -> Container(...)}
return containers.associateBy({ it.id }, { it }
}
private fun mapOperations(remoteInstance: InstanceRemoteModel): Map<String, Operation> {
...
}
}
My question is : How to properly test the mapper? Note that mapOperations
and mapContainers
are private functions.