library/room: defaults-mask and keystore-adjacent coverage (#tests)
- Commit
1f910ef5f27ead057542c1afe1f551e20bcf1700- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-16 14:34 UTC (20 days ago)
- Parents
95a31d1
Adds partially-omitted-argument calls through the reified buildDatabase wrapper (each omission a different defaults-mask combination at the Kotlin call site) and pins that the reified defaults synthetic refuses direct invocation - it exists only for inlining, which is why its instructions are unreachable. Coverage (createMergedCoverageReport, instruction): library/room 70.2% (548/781) -> 73.1% (571/781). Ceiling (210 missed): encryptExistingDatabase's SQLCipher export block (88) and SqlCipherDbCodec's native export/import (55) need libsqlcipher - the AAR's x86_64 .so is bionic-linked and cannot load on the glibc host JVM; the password-from-keystore branch (20) needs AndroidKeyStore, which Robolectric does not provide (the existing suite asserts its KeyStoreException); and the reified defaults synthetic (52) throws by design when invoked. The happy paths run in the on-device DeviceDatabaseTest. Verified: :library:room:testDebugUnitTest, detekt and lint green without the ignore-failures init script.
Diff
library/room/src/test/java/com/vayunmathur/library/room/BuildDatabaseTest.kt
diff --git a/library/room/src/test/java/com/vayunmathur/library/room/BuildDatabaseTest.kt b/library/room/src/test/java/com/vayunmathur/library/room/BuildDatabaseTest.ktindex 9dd2b5f153..a6f811e3bf 100644--- a/library/room/src/test/java/com/vayunmathur/library/room/BuildDatabaseTest.kt+++ b/library/room/src/test/java/com/vayunmathur/library/room/BuildDatabaseTest.kt@@ -145,6 +145,40 @@ class BuildDatabaseTest { db.close() } + @Test+ fun `reified overload with partially omitted arguments uses the defaults mask`() {+ // Each call omits a different subset, exercising the synthetic+ // $default constructor-mask branches of the reified wrapper.+ val a = context.buildDatabase<TestDatabase>(encryptionPassword = "pw", dbName = "mask-a-db")+ assertSame(a, databases[TestDatabase::class])+ databases.clear()+ val b = context.buildDatabase<TestDatabase>(null, "pw", "mask-b-db", false)+ assertSame(b, databases[TestDatabase::class])+ databases.clear()+ val c = context.buildDatabase<TestDatabase>(migrations = emptyList(), encryptionPassword = "pw")+ assertSame(c, databases[TestDatabase::class])+ }++ @Test+ fun `synthetic defaults method refuses direct invocation for the reified overload`() {+ // The reified wrapper's $default synthetic exists only for the+ // compiler: invoked directly it must refuse, because a reified+ // type parameter has no runtime value. This is why those 40-odd+ // instructions are unreachable from any test (see coverage note).+ val method = Class.forName("com.vayunmathur.library.room.SqlCipherKt")+ .getDeclaredMethod(+ "buildDatabase\u0024default",+ Context::class.java, List::class.java, String::class.java,+ String::class.java, Boolean::class.javaPrimitiveType,+ Int::class.javaPrimitiveType, Any::class.java,+ )+ method.isAccessible = true+ val thrown = kotlin.test.assertFailsWith<java.lang.reflect.InvocationTargetException> {+ method.invoke(null, context, null, "pw", "defaultmask-db", false, 1, null)+ }+ kotlin.test.assertTrue(thrown.cause is UnsupportedOperationException)+ }+ @Test fun `the dao is reachable without opening the database`() { // Opening is deferred until first use: the generated DAO must already