Skip to content

Instantly share code, notes, and snippets.

@oharaandrew314
Last active December 6, 2022 21:36
Show Gist options
  • Save oharaandrew314/92f02585f33243e369ea02f09a1466ac to your computer and use it in GitHub Desktop.
Save oharaandrew314/92f02585f33243e369ea02f09a1466ac to your computer and use it in GitHub Desktop.
import io.kotest.matchers.collections.shouldBeEmpty
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
import java.util.UUID
private val ownerId = UUID.randomUUID()
private val kratos = Cat(
id = UUID.randomUUID(),
ownerId = ownerId,
name = "Kratos"
)
private val athena = Cat(
id = UUID.randomUUID(),
ownerId = ownerId,
name = "Athena"
)
abstract class CatsRepoContract(private val repo: CatsRepo) {
init {
repo += kratos
repo += athena
}
@Test
fun `get missing`() {
repo[UUID.randomUUID()] shouldBe null
}
@Test
fun `get single`() {
repo[kratos.id] shouldBe kratos
}
@Test
fun `list for missing owner`() {
repo.listForOwner(UUID.randomUUID()).shouldBeEmpty()
}
@Test
fun `list for owner`() {
repo.listForOwner(ownerId).shouldContainExactlyInAnyOrder(kratos, athena)
}
@Test
fun `delete missing`() {
repo -= UUID.randomUUID()
}
@Test
fun `delete existing`() {
repo -= kratos.id
repo[kratos.id] shouldBe null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment