Skip to content

Instantly share code, notes, and snippets.

@oharaandrew314
Created December 6, 2022 21:37
Show Gist options
  • Save oharaandrew314/02105c3c073c5150f65e534ab59ef52e to your computer and use it in GitHub Desktop.
Save oharaandrew314/02105c3c073c5150f65e534ab59ef52e to your computer and use it in GitHub Desktop.
dependencies {
testImplementation("com.h2database:h2:2.1.214")
}
import org.h2.jdbcx.JdbcDataSource
import java.util.UUID
import javax.sql.DataSource
private fun testDb(): DataSource {
val dataSource = JdbcDataSource().apply {
setURL("jdbc:h2:mem:${UUID.randomUUID()};MODE=MySQL;DB_CLOSE_DELAY=-1")
this.user = "sa"
this.password = ""
}
dataSource.connection.use { conn ->
conn.prepareStatement(
"CREATE TABLE cats (id CHAR(36) PRIMARY KEY NOT NULL, ownerId CHAR(36) NOT NULL, name TEXT NOT NULL)"
).executeUpdate()
}
return dataSource
}
class JdbcCatsRepoTest: CatsRepoContract(JdbcCatsRepo(testDb()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment