Adds MigrateSessionTo032Test
This commit is contained in:
parent
c6728dde38
commit
051f925f0e
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.matrix.android.sdk.internal.database.migration
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
import org.matrix.android.sdk.test.fakes.FakeDynamicRealm
|
||||||
|
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields
|
||||||
|
|
||||||
|
internal class MigrateSessionTo032Test {
|
||||||
|
|
||||||
|
private val fakeDynamicRealm = FakeDynamicRealm()
|
||||||
|
private val migrator = MigrateSessionTo032(fakeDynamicRealm.instance)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when doMigrate, then directParentNames added`() {
|
||||||
|
migrator.doMigrate(fakeDynamicRealm.instance)
|
||||||
|
|
||||||
|
fakeDynamicRealm.fakeRealmSchema.withObjectSchema("RoomSummaryEntity")
|
||||||
|
.verifyListFieldAdded(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, String::class.java)
|
||||||
|
.verifyStringTransformation(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, "")
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.matrix.android.sdk.test.fakes
|
||||||
|
|
||||||
|
import io.mockk.every
|
||||||
|
import io.mockk.mockk
|
||||||
|
import io.realm.DynamicRealm
|
||||||
|
|
||||||
|
class FakeDynamicRealm(
|
||||||
|
val fakeRealmSchema: FakeRealmSchema = FakeRealmSchema()
|
||||||
|
) {
|
||||||
|
|
||||||
|
val instance: DynamicRealm = mockk {
|
||||||
|
every { schema } returns fakeRealmSchema.instance
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.matrix.android.sdk.test.fakes
|
||||||
|
|
||||||
|
import io.mockk.justRun
|
||||||
|
import io.mockk.mockk
|
||||||
|
import io.mockk.verify
|
||||||
|
import io.realm.DynamicRealmObject
|
||||||
|
|
||||||
|
class FakeDynamicRealmObject {
|
||||||
|
|
||||||
|
val instance: DynamicRealmObject = mockk {
|
||||||
|
justRun { setString(any(), any()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun verifySetString(fieldName: String, value: String) {
|
||||||
|
verify { instance.setString(fieldName, value) }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.matrix.android.sdk.test.fakes
|
||||||
|
|
||||||
|
import io.mockk.every
|
||||||
|
import io.mockk.mockk
|
||||||
|
import io.mockk.slot
|
||||||
|
import io.mockk.verify
|
||||||
|
import io.realm.RealmObjectSchema
|
||||||
|
import io.realm.RealmObjectSchema.Function
|
||||||
|
|
||||||
|
class FakeRealmObjectSchema(
|
||||||
|
private val fakeDynamicRealmObject: FakeDynamicRealmObject = FakeDynamicRealmObject()
|
||||||
|
) {
|
||||||
|
|
||||||
|
val instance: RealmObjectSchema = mockk {
|
||||||
|
every { addRealmListField(any(), any<Class<*>>()) } returns this
|
||||||
|
every { transform(any()) } returns this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun verifyListFieldAdded(fieldName: String, type: Class<*>) = apply {
|
||||||
|
verify { instance.addRealmListField(fieldName, type) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun verifyStringTransformation(fieldName: String, transformedInto: String) = apply {
|
||||||
|
val transformationSlot = slot<Function>()
|
||||||
|
verify { instance.transform(capture(transformationSlot)) }
|
||||||
|
transformationSlot.captured.apply(fakeDynamicRealmObject.instance)
|
||||||
|
fakeDynamicRealmObject.verifySetString(fieldName, transformedInto)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.matrix.android.sdk.test.fakes
|
||||||
|
|
||||||
|
import io.mockk.every
|
||||||
|
import io.mockk.mockk
|
||||||
|
import io.mockk.verify
|
||||||
|
import io.realm.RealmSchema
|
||||||
|
|
||||||
|
class FakeRealmSchema(
|
||||||
|
private val fakeRealmObjectSchema: FakeRealmObjectSchema = FakeRealmObjectSchema()
|
||||||
|
) {
|
||||||
|
|
||||||
|
val instance: RealmSchema = mockk {
|
||||||
|
every { this@mockk.get(any()) } returns fakeRealmObjectSchema.instance
|
||||||
|
}
|
||||||
|
|
||||||
|
fun withObjectSchema(className: String): FakeRealmObjectSchema {
|
||||||
|
verify { instance.get(className) }
|
||||||
|
return fakeRealmObjectSchema
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user