From 3f35615e88a8f77c6bcdae9b782c22e709c3bc9c Mon Sep 17 00:00:00 2001 From: JaniruTEC <52893617+JaniruTEC@users.noreply.github.com> Date: Sun, 4 Aug 2024 22:43:49 +0200 Subject: [PATCH] Added type-checks to tests for "MappingSupportSQLiteQuery" Added "@VisibleForTesting" to "MappingSupportSQLiteQuery" and changed its visibility to internal *This commit is related to issue #529 [1]* [1] https://github.com/cryptomator/android/issues/529 --- .../MappingSupportSQLiteDatabase.kt | 3 +- .../MappingSupportSQLiteDatabaseTest.kt | 32 +++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/data/src/main/java/org/cryptomator/data/db/sqlmapping/MappingSupportSQLiteDatabase.kt b/data/src/main/java/org/cryptomator/data/db/sqlmapping/MappingSupportSQLiteDatabase.kt index 45640f4a7..774774e59 100644 --- a/data/src/main/java/org/cryptomator/data/db/sqlmapping/MappingSupportSQLiteDatabase.kt +++ b/data/src/main/java/org/cryptomator/data/db/sqlmapping/MappingSupportSQLiteDatabase.kt @@ -179,7 +179,8 @@ internal class MappingSupportSQLiteDatabase( } } - private inner class MappingSupportSQLiteQuery( + @VisibleForTesting + internal inner class MappingSupportSQLiteQuery( private val delegateQuery: SupportSQLiteQuery ) : SupportSQLiteQuery by delegateQuery { diff --git a/data/src/test/java/org/cryptomator/data/db/sqlmapping/MappingSupportSQLiteDatabaseTest.kt b/data/src/test/java/org/cryptomator/data/db/sqlmapping/MappingSupportSQLiteDatabaseTest.kt index 448994d58..8721e1408 100644 --- a/data/src/test/java/org/cryptomator/data/db/sqlmapping/MappingSupportSQLiteDatabaseTest.kt +++ b/data/src/test/java/org/cryptomator/data/db/sqlmapping/MappingSupportSQLiteDatabaseTest.kt @@ -16,6 +16,7 @@ import androidx.sqlite.db.SupportSQLiteStatement import org.cryptomator.data.db.sqlmapping.Mapping.COMMENT import org.cryptomator.data.db.sqlmapping.Mapping.COUNTER import org.cryptomator.data.db.sqlmapping.Mapping.IDENTITY +import org.cryptomator.data.db.sqlmapping.MappingSupportSQLiteDatabase.MappingSupportSQLiteQuery import org.cryptomator.data.db.sqlmapping.MappingSupportSQLiteDatabase.MappingSupportSQLiteStatement import org.cryptomator.data.testing.ValueExtractor import org.cryptomator.data.testing.anyPseudoEquals @@ -51,6 +52,7 @@ import org.mockito.Mockito.verifyNoMoreInteractions import org.mockito.internal.verification.VerificationModeFactory.times import org.mockito.invocation.InvocationOnMock import org.mockito.kotlin.KInOrder +import org.mockito.kotlin.and import org.mockito.kotlin.anyArray import org.mockito.kotlin.eq import org.mockito.kotlin.inOrder @@ -140,10 +142,16 @@ class MappingSupportSQLiteDatabaseTest { val supportSQLiteQueryProperties = newCachedSupportSQLiteQueryProperties() verify(delegateMock).query( // - anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `id_test`"), supportSQLiteQueryProperties) + and( // + reifiedAny(), // + anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `id_test`"), supportSQLiteQueryProperties) // + ) ) verify(delegateMock).query( // - anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `comment_test` -- Comment!"), supportSQLiteQueryProperties) + and( // + reifiedAny(), // + anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `comment_test` -- Comment!"), supportSQLiteQueryProperties) // + ) ) verifyNoMoreInteractions(delegateMock) } @@ -157,10 +165,16 @@ class MappingSupportSQLiteDatabaseTest { val supportSQLiteQueryProperties = newCachedSupportSQLiteQueryProperties() verify(delegateMock).query( // - anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `id_test` WHERE `col` = ?", arrayOf("test1")), supportSQLiteQueryProperties) + and( // + reifiedAny(), // + anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `id_test` WHERE `col` = ?", arrayOf("test1")), supportSQLiteQueryProperties) // + ) ) verify(delegateMock).query( // - anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `comment_test` WHERE `col` = ? -- Comment!", arrayOf("test2")), supportSQLiteQueryProperties) + and( // + reifiedAny(), // + anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `comment_test` WHERE `col` = ? -- Comment!", arrayOf("test2")), supportSQLiteQueryProperties) // + ) ) verifyNoMoreInteractions(delegateMock) } @@ -175,11 +189,17 @@ class MappingSupportSQLiteDatabaseTest { val supportSQLiteQueryProperties = newCachedSupportSQLiteQueryProperties() verify(delegateMock).query( // - anyPseudoEquals(queries.idExpected, supportSQLiteQueryProperties), // + and( + reifiedAny(), // + anyPseudoEquals(queries.idExpected, supportSQLiteQueryProperties), // + ), // anyPseudoEqualsUnlessNull(signals.idExpected, setOf>(CancellationSignal::isCanceled)) ) verify(delegateMock).query( // - anyPseudoEquals(queries.commentExpected, supportSQLiteQueryProperties), // + and( + reifiedAny(), // + anyPseudoEquals(queries.commentExpected, supportSQLiteQueryProperties), // + ), // anyPseudoEqualsUnlessNull(signals.commentExpected, setOf>(CancellationSignal::isCanceled)) ) verifyNoMoreInteractions(delegateMock)