Skip to content

Commit 9949779

Browse files
committed
ensuring the store migration class is always equal to other store migration instances
- is needed as realm will throw if multiple migration instances are created and they don't match
1 parent 540036f commit 9949779

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ internal class RealmSessionStoreMigration @Inject constructor(
5757
const val SESSION_STORE_SCHEMA_VERSION = 19L
5858
}
5959

60+
/**
61+
* Forces all RealmSessionStoreMigration instances to be equal
62+
* Avoids Realm throwing when multiple instances of the migration are set
63+
*/
64+
override fun equals(other: Any?) = other is RealmSessionStoreMigration
65+
override fun hashCode() = 1000
66+
6067
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
6168
Timber.v("Migrating Realm Session from $oldVersion to $newVersion")
6269

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2021 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.matrix.android.sdk.internal.database
18+
19+
import io.mockk.mockk
20+
import org.amshove.kluent.shouldBeEqualTo
21+
import org.junit.Test
22+
23+
class RealmSessionStoreMigrationTest {
24+
25+
@Test
26+
fun `when creating multiple migration instances then they are equal`() {
27+
RealmSessionStoreMigration(normalizer = mockk()) shouldBeEqualTo RealmSessionStoreMigration(normalizer = mockk())
28+
}
29+
}

0 commit comments

Comments
 (0)