Hi there! I’m trying to cover the logic based on E...
# exposed
l
Hi there! I’m trying to cover the logic based on Exposed with unit tests and faced to a problem - how to create an entity manually to mock repository calls. Found the solution that works for “simple” entity fields but how to set manually entity relations?
Copy code
class MyEntity(id: EntityID<UUID>) : UUIDEntity(id) {
    companion object : UUIDEntityClass<MyEntity>(MyEntities)
    var name by Migs.name
    var unit by Migs.unit
    val relations by MyRelationEntity referrersOn MyRelations.id
}

val myFieldIndex: Map<Expression<*>, Int> = mapOf(
        MyEntities.id to 0,
        MyEntities.name to 1,
        MyEntities.unit to 2,
)

val myResultRowData = arrayOfNulls<Any?>(3)
myResultRowData[0]=1
myResultRowData[1]="Name1"
myResultRowData[2]="Unit1"

val e = MyEntity(EntityID(UUID.randomUUID(), Migs))
e._readValues = ResultRow(fieldIndex = myFieldIndex, data = myResultRowData)

// e.setRelations < --- how to set relations ???
h
I would use a new layer: repositories with domain classes.
l
@hfhbd you mean repository should return domain objects rather than entities?
h
yes
👍 1
l
Seems it will be the best solution, thanks!