How to mock DB Queries in Kotlin's Exposed?

1.3k views Asked by At

I'm currently writing an application using the Kotlin ORM Exposed. I am trying to test some basic functionality where I convert the query results to an instance of the corresponding object. I have something along the lines of the following:

    suspend fun getAllFoo(): List<Foo> = newSuspendedTransaction {
        FooTable.selectAll().map { rowToFoo(it) }
    }

    private fun rowToFoo(row: ResultRow): Foo {
        return Foo(
            id = row[Foo.id],
            description = row[Foo.description]
        )
    }

(bare with me as I omit the code for the data class, as I don't think it's super relevant). My question is, how do I mock the selectAll() function? I have tried

        val mockFoo = mock<Foo> {
            on { selectAll() }.doReturn(???)
        }

but I do not know what to add to the mocked return, because the query results seem to be somewhat cryptic internal classes, any ideas?

0

There are 0 answers