Gustav Elmgren
12/01/2022, 8:38 AMProperty klass should be initialized before get.
which I guess is related that I do not have any relations given I just wanna return a dumb empty entity object for now.Andrew O'Hara
12/01/2022, 1:49 PMGustav Elmgren
12/01/2022, 2:32 PMGustav Elmgren
12/01/2022, 2:32 PMGustav Elmgren
12/01/2022, 2:33 PMwhen(myRepository).findSomething().thenReturn(MyDAOObject)
Andrew O'Hara
12/01/2022, 6:01 PMdata class Cat(val id: Int, val name: String)
interface CatRepo {
operator fun get(id: Int): Cat?
}
class ExposedCatRepo: CatRepo {
.....
}
How do you have your access-patterns architected?Gustav Elmgren
12/01/2022, 6:03 PMGustav Elmgren
12/01/2022, 6:05 PMAndrew O'Hara
12/01/2022, 6:09 PMGustav Elmgren
12/01/2022, 6:10 PMAndrew O'Hara
12/01/2022, 6:12 PMinterface CatRepo {
operator fun get(id: Int): Cat?
}
class ExposedCatRepo: CatRepo {
...
}
class FakeCatRepo: CatRepo {
val cats = mutableListOf<Cat>()
override fun get(id: Int) = cats.find { it.id == id}
}
Gustav Elmgren
12/01/2022, 6:14 PM@Test
fun `my awesometest`() {
val cat = Cat(EntityId(1L, LongIdTable())
when(myRepoMock).find(1L).thenReturn(cat)
}
Andrew O'Hara
12/01/2022, 6:17 PMGustav Elmgren
12/01/2022, 6:17 PMGustav Elmgren
12/01/2022, 6:18 PMGustav Elmgren
12/01/2022, 6:18 PMAndrew O'Hara
12/01/2022, 6:21 PMAndrew O'Hara
12/01/2022, 6:24 PMGustav Elmgren
12/01/2022, 6:43 PMGustav Elmgren
12/01/2022, 6:46 PMGustav Elmgren
12/01/2022, 6:47 PMGustav Elmgren
12/01/2022, 6:49 PMCats
table a Cat
DAO and a CatModel
with all the same properties almost. And not using DAO is sometimes problematic for fetching relations imo. It gives some value, but dunno if the trouble is worth it.Andrew O'Hara
12/01/2022, 7:10 PMTestDriver
class to perform common setup tasks and hold the entrypoints into the app.
I agree the exposed-dao module makes it much easier to fetch relations, but then the tradeoff is an extra layer between the database and your data classes. As a personal rule, I would never have my repository return an exposed entity or ResultSet anyway; because your business logic calling the repository must then be polluted with the database transaction.Gustav Elmgren
12/02/2022, 1:52 PMGustav Elmgren
12/02/2022, 1:53 PM