Skip to content
Snippets Groups Projects
Commit 8a4fb43a authored by Sebastian's avatar Sebastian
Browse files

Add test that creates database on Android

parent 0ead2a80
No related branches found
No related tags found
No related merge requests found
Pipeline #7355 failed
......@@ -78,8 +78,11 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'
}
def torBinariesDir = 'src/main/res/raw'
......
package org.briarproject.mailbox.core
import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.sqlite.mc.SQLiteMCConfig
import java.nio.file.Files
import java.nio.file.Path
import java.sql.Connection
import java.sql.DriverManager
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class DatabaseCreationTest {
@Test
fun createDatabase(): Unit = runBlocking {
val file: Path = Files.createTempFile("test", ".sqlite")
println(file)
val connection: Connection = DriverManager.getConnection("jdbc:sqlite:$file",
SQLiteMCConfig().withKey("very-secret").toProperties())
val stmt = connection.createStatement()
stmt.executeUpdate("CREATE TABLE students (id integer, name string)")
stmt.executeUpdate("INSERT INTO students values (1, 'alice')")
stmt.executeUpdate("INSERT INTO students values (2, 'bob')")
val prep = connection.prepareStatement("SELECT * FROM students")
val results = prep.executeQuery()
for (i in 0..1) {
val available = results.next()
assertTrue(available)
val id = results.getInt(1)
val name = results.getString(2)
when (i) {
0 -> {
assertEquals(1, id)
assertEquals("alice", name)
}
1 -> {
assertEquals(2, id)
assertEquals("bob", name)
}
}
}
Files.delete(file)
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment