Skip to content

Commit 3f35615

Browse files
committed
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] #529
1 parent c581e77 commit 3f35615

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

data/src/main/java/org/cryptomator/data/db/sqlmapping/MappingSupportSQLiteDatabase.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ internal class MappingSupportSQLiteDatabase(
179179
}
180180
}
181181

182-
private inner class MappingSupportSQLiteQuery(
182+
@VisibleForTesting
183+
internal inner class MappingSupportSQLiteQuery(
183184
private val delegateQuery: SupportSQLiteQuery
184185
) : SupportSQLiteQuery by delegateQuery {
185186

data/src/test/java/org/cryptomator/data/db/sqlmapping/MappingSupportSQLiteDatabaseTest.kt

+26-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import androidx.sqlite.db.SupportSQLiteStatement
1616
import org.cryptomator.data.db.sqlmapping.Mapping.COMMENT
1717
import org.cryptomator.data.db.sqlmapping.Mapping.COUNTER
1818
import org.cryptomator.data.db.sqlmapping.Mapping.IDENTITY
19+
import org.cryptomator.data.db.sqlmapping.MappingSupportSQLiteDatabase.MappingSupportSQLiteQuery
1920
import org.cryptomator.data.db.sqlmapping.MappingSupportSQLiteDatabase.MappingSupportSQLiteStatement
2021
import org.cryptomator.data.testing.ValueExtractor
2122
import org.cryptomator.data.testing.anyPseudoEquals
@@ -51,6 +52,7 @@ import org.mockito.Mockito.verifyNoMoreInteractions
5152
import org.mockito.internal.verification.VerificationModeFactory.times
5253
import org.mockito.invocation.InvocationOnMock
5354
import org.mockito.kotlin.KInOrder
55+
import org.mockito.kotlin.and
5456
import org.mockito.kotlin.anyArray
5557
import org.mockito.kotlin.eq
5658
import org.mockito.kotlin.inOrder
@@ -140,10 +142,16 @@ class MappingSupportSQLiteDatabaseTest {
140142

141143
val supportSQLiteQueryProperties = newCachedSupportSQLiteQueryProperties()
142144
verify(delegateMock).query( //
143-
anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `id_test`"), supportSQLiteQueryProperties)
145+
and( //
146+
reifiedAny<MappingSupportSQLiteQuery>(), //
147+
anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `id_test`"), supportSQLiteQueryProperties) //
148+
)
144149
)
145150
verify(delegateMock).query( //
146-
anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `comment_test` -- Comment!"), supportSQLiteQueryProperties)
151+
and( //
152+
reifiedAny<MappingSupportSQLiteQuery>(), //
153+
anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `comment_test` -- Comment!"), supportSQLiteQueryProperties) //
154+
)
147155
)
148156
verifyNoMoreInteractions(delegateMock)
149157
}
@@ -157,10 +165,16 @@ class MappingSupportSQLiteDatabaseTest {
157165

158166
val supportSQLiteQueryProperties = newCachedSupportSQLiteQueryProperties()
159167
verify(delegateMock).query( //
160-
anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `id_test` WHERE `col` = ?", arrayOf("test1")), supportSQLiteQueryProperties)
168+
and( //
169+
reifiedAny<MappingSupportSQLiteQuery>(), //
170+
anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `id_test` WHERE `col` = ?", arrayOf("test1")), supportSQLiteQueryProperties) //
171+
)
161172
)
162173
verify(delegateMock).query( //
163-
anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `comment_test` WHERE `col` = ? -- Comment!", arrayOf("test2")), supportSQLiteQueryProperties)
174+
and( //
175+
reifiedAny<MappingSupportSQLiteQuery>(), //
176+
anyPseudoEquals(SimpleSQLiteQuery("SELECT `col` FROM `comment_test` WHERE `col` = ? -- Comment!", arrayOf("test2")), supportSQLiteQueryProperties) //
177+
)
164178
)
165179
verifyNoMoreInteractions(delegateMock)
166180
}
@@ -175,11 +189,17 @@ class MappingSupportSQLiteDatabaseTest {
175189

176190
val supportSQLiteQueryProperties = newCachedSupportSQLiteQueryProperties()
177191
verify(delegateMock).query( //
178-
anyPseudoEquals(queries.idExpected, supportSQLiteQueryProperties), //
192+
and(
193+
reifiedAny<MappingSupportSQLiteQuery>(), //
194+
anyPseudoEquals(queries.idExpected, supportSQLiteQueryProperties), //
195+
), //
179196
anyPseudoEqualsUnlessNull(signals.idExpected, setOf<ValueExtractor<CancellationSignal>>(CancellationSignal::isCanceled))
180197
)
181198
verify(delegateMock).query( //
182-
anyPseudoEquals(queries.commentExpected, supportSQLiteQueryProperties), //
199+
and(
200+
reifiedAny<MappingSupportSQLiteQuery>(), //
201+
anyPseudoEquals(queries.commentExpected, supportSQLiteQueryProperties), //
202+
), //
183203
anyPseudoEqualsUnlessNull(signals.commentExpected, setOf<ValueExtractor<CancellationSignal>>(CancellationSignal::isCanceled))
184204
)
185205
verifyNoMoreInteractions(delegateMock)

0 commit comments

Comments
 (0)