diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPusherTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPusherTask.kt index c284f006ca..3e145dc668 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPusherTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPusherTask.kt @@ -38,6 +38,7 @@ internal class DefaultAddPusherTask @Inject constructor( private val requestExecutor: RequestExecutor, private val globalErrorReceiver: GlobalErrorReceiver ) : AddPusherTask { + override suspend fun execute(params: AddPusherTask.Params) { val pusher = params.pusher try { diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/mapper/PushersMapperTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/mapper/PushersMapperTest.kt new file mode 100644 index 0000000000..5bca9248d6 --- /dev/null +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/mapper/PushersMapperTest.kt @@ -0,0 +1,64 @@ +/* + * 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.mapper + +import org.amshove.kluent.shouldBeEqualTo +import org.junit.Test +import org.matrix.android.sdk.test.fixtures.JsonPusherFixture.aJsonPusher +import org.matrix.android.sdk.test.fixtures.PusherEntityFixture.aPusherEntity + +class PushersMapperTest { + + @Test + fun `when mapping PusherEntity, then it is mapped into Pusher successfully`() { + val pusherEntity = aPusherEntity() + + val mappedPusher = PushersMapper.map(pusherEntity) + + mappedPusher.pushKey shouldBeEqualTo pusherEntity.pushKey + mappedPusher.kind shouldBeEqualTo pusherEntity.kind.orEmpty() + mappedPusher.appId shouldBeEqualTo pusherEntity.appId + mappedPusher.appDisplayName shouldBeEqualTo pusherEntity.appDisplayName + mappedPusher.deviceDisplayName shouldBeEqualTo pusherEntity.deviceDisplayName + mappedPusher.profileTag shouldBeEqualTo pusherEntity.profileTag + mappedPusher.lang shouldBeEqualTo pusherEntity.lang + mappedPusher.data.url shouldBeEqualTo pusherEntity.data?.url + mappedPusher.data.format shouldBeEqualTo pusherEntity.data?.format + mappedPusher.enabled shouldBeEqualTo pusherEntity.enabled + mappedPusher.deviceId shouldBeEqualTo pusherEntity.deviceId + mappedPusher.state shouldBeEqualTo pusherEntity.state + } + + @Test + fun `when mapping JsonPusher, then it is mapped into Pusher successfully`() { + val jsonPusher = aJsonPusher() + + val mappedPusherEntity = PushersMapper.map(jsonPusher) + + mappedPusherEntity.pushKey shouldBeEqualTo jsonPusher.pushKey + mappedPusherEntity.kind shouldBeEqualTo jsonPusher.kind + mappedPusherEntity.appId shouldBeEqualTo jsonPusher.appId + mappedPusherEntity.appDisplayName shouldBeEqualTo jsonPusher.appDisplayName + mappedPusherEntity.deviceDisplayName shouldBeEqualTo jsonPusher.deviceDisplayName + mappedPusherEntity.profileTag shouldBeEqualTo jsonPusher.profileTag + mappedPusherEntity.lang shouldBeEqualTo jsonPusher.lang + mappedPusherEntity.data?.url shouldBeEqualTo jsonPusher.data?.url + mappedPusherEntity.data?.format shouldBeEqualTo jsonPusher.data?.format + mappedPusherEntity.enabled shouldBeEqualTo jsonPusher.enabled + mappedPusherEntity.deviceId shouldBeEqualTo jsonPusher.deviceId + } +} diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/pushers/DefaultAddPusherTaskTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/pushers/DefaultAddPusherTaskTest.kt index dac33069f3..a971973f56 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/pushers/DefaultAddPusherTaskTest.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/pushers/DefaultAddPusherTaskTest.kt @@ -71,7 +71,7 @@ class DefaultAddPusherTaskTest { } @Test - fun `given a persisted pusher when adding Pusher then updates api and mutates persisted result with Registered state`() { + fun `given a persisted pusher, when adding Pusher, then updates api and mutates persisted result with Registered state`() { val realmResult = PusherEntity(appDisplayName = null) monarchy.givenWhereReturns(result = realmResult) .givenEqualTo(PusherEntityFields.PUSH_KEY, A_JSON_PUSHER.pushKey) @@ -85,7 +85,7 @@ class DefaultAddPusherTaskTest { } @Test - fun `given a persisted push entity and SetPush API fails when adding Pusher then mutates persisted result with Failed registration state and rethrows`() { + fun `given a persisted push entity and SetPush API fails, when adding Pusher, then mutates persisted result with Failed registration state and rethrows`() { val realmResult = PusherEntity() monarchy.givenWhereReturns(result = realmResult) .givenEqualTo(PusherEntityFields.PUSH_KEY, A_JSON_PUSHER.pushKey) @@ -99,7 +99,7 @@ class DefaultAddPusherTaskTest { } @Test - fun `given no persisted push entity and SetPush API fails when adding Pusher then rethrows error`() { + fun `given no persisted push entity and SetPush API fails, when adding Pusher, then rethrows error`() { monarchy.givenWhereReturns(result = null) .givenEqualTo(PusherEntityFields.PUSH_KEY, A_JSON_PUSHER.pushKey) pushersAPI.givenSetPusherErrors(SocketException()) diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fixtures/JsonPusherFixture.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fixtures/JsonPusherFixture.kt new file mode 100644 index 0000000000..56b5dcc940 --- /dev/null +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fixtures/JsonPusherFixture.kt @@ -0,0 +1,49 @@ +/* + * 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.fixtures + +import org.matrix.android.sdk.internal.session.pushers.JsonPusher +import org.matrix.android.sdk.internal.session.pushers.JsonPusherData + +internal object JsonPusherFixture { + + fun aJsonPusher( + pushKey: String = "", + kind: String? = null, + appId: String = "", + appDisplayName: String? = null, + deviceDisplayName: String? = null, + profileTag: String? = null, + lang: String? = null, + data: JsonPusherData? = null, + append: Boolean? = false, + enabled: Boolean = true, + deviceId: String? = null, + ) = JsonPusher( + pushKey, + kind, + appId, + appDisplayName, + deviceDisplayName, + profileTag, + lang, + data, + append, + enabled, + deviceId, + ) +} diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fixtures/PusherEntityFixture.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fixtures/PusherEntityFixture.kt new file mode 100644 index 0000000000..9e3fc555be --- /dev/null +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fixtures/PusherEntityFixture.kt @@ -0,0 +1,47 @@ +/* + * 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.fixtures + +import org.matrix.android.sdk.internal.database.model.PusherDataEntity +import org.matrix.android.sdk.internal.database.model.PusherEntity + +internal object PusherEntityFixture { + + fun aPusherEntity( + pushKey: String = "", + kind: String? = null, + appId: String = "", + appDisplayName: String? = null, + deviceDisplayName: String? = null, + profileTag: String? = null, + lang: String? = null, + data: PusherDataEntity? = null, + enabled: Boolean = true, + deviceId: String? = null, + ) = PusherEntity( + pushKey, + kind, + appId, + appDisplayName, + deviceDisplayName, + profileTag, + lang, + data, + enabled, + deviceId, + ) +}