Skip to content

Commit

Permalink
Added type-checks to tests for "MappingSupportSQLiteQuery"
Browse files Browse the repository at this point in the history
Added "@VisibleForTesting" to "MappingSupportSQLiteQuery" and changed its visibility to internal

*This commit is related to issue #529 [1]*

[1] #529
  • Loading branch information
JaniruTEC committed Sep 25, 2024
1 parent c581e77 commit 3f35615
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ internal class MappingSupportSQLiteDatabase(
}
}

private inner class MappingSupportSQLiteQuery(
@VisibleForTesting
internal inner class MappingSupportSQLiteQuery(
private val delegateQuery: SupportSQLiteQuery
) : SupportSQLiteQuery by delegateQuery {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -140,10 +142,16 @@ class MappingSupportSQLiteDatabaseTest {

val supportSQLiteQueryProperties = newCachedSupportSQLiteQueryProperties()
verify(delegateMock).query( //
anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `id_test`"), supportSQLiteQueryProperties)
and( //
reifiedAny<MappingSupportSQLiteQuery>(), //
anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `id_test`"), supportSQLiteQueryProperties) //
)
)
verify(delegateMock).query( //
anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `comment_test` -- Comment!"), supportSQLiteQueryProperties)
and( //
reifiedAny<MappingSupportSQLiteQuery>(), //
anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `comment_test` -- Comment!"), supportSQLiteQueryProperties) //
)
)
verifyNoMoreInteractions(delegateMock)
}
Expand All @@ -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<MappingSupportSQLiteQuery>(), //
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<MappingSupportSQLiteQuery>(), //
anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `comment_test` WHERE `col` = ? -- Comment!", arrayOf("test2")), supportSQLiteQueryProperties) //
)
)
verifyNoMoreInteractions(delegateMock)
}
Expand All @@ -175,11 +189,17 @@ class MappingSupportSQLiteDatabaseTest {

val supportSQLiteQueryProperties = newCachedSupportSQLiteQueryProperties()
verify(delegateMock).query( //
anyPseudoEquals(queries.idExpected, supportSQLiteQueryProperties), //
and(
reifiedAny<MappingSupportSQLiteQuery>(), //
anyPseudoEquals(queries.idExpected, supportSQLiteQueryProperties), //
), //
anyPseudoEqualsUnlessNull(signals.idExpected, setOf<ValueExtractor<CancellationSignal>>(CancellationSignal::isCanceled))
)
verify(delegateMock).query( //
anyPseudoEquals(queries.commentExpected, supportSQLiteQueryProperties), //
and(
reifiedAny<MappingSupportSQLiteQuery>(), //
anyPseudoEquals(queries.commentExpected, supportSQLiteQueryProperties), //
), //
anyPseudoEqualsUnlessNull(signals.commentExpected, setOf<ValueExtractor<CancellationSignal>>(CancellationSignal::isCanceled))
)
verifyNoMoreInteractions(delegateMock)
Expand Down

0 comments on commit 3f35615

Please sign in to comment.