From 40b059147824e2508323527597089844e89825d4 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Mon, 3 Apr 2023 16:27:34 +0200 Subject: [PATCH] Move FakeSelectUserPresenter to dedicated module --- features/createroom/impl/build.gradle.kts | 1 + .../impl/addpeople/AddPeoplePresenterTests.kt | 8 ++--- .../impl/root/CreateRoomRootPresenterTests.kt | 17 +-------- features/selectusers/test/build.gradle.kts | 28 +++++++++++++++ .../test/FakeSelectUserPresenter.kt | 36 +++++++++++++++++++ .../test/FakeSelectUserPresenterFactory.kt | 25 +++++++++++++ 6 files changed, 93 insertions(+), 22 deletions(-) create mode 100644 features/selectusers/test/build.gradle.kts create mode 100644 features/selectusers/test/src/main/kotlin/io/element/android/features/selectusers/test/FakeSelectUserPresenter.kt create mode 100644 features/selectusers/test/src/main/kotlin/io/element/android/features/selectusers/test/FakeSelectUserPresenterFactory.kt diff --git a/features/createroom/impl/build.gradle.kts b/features/createroom/impl/build.gradle.kts index 366cc1e0bd..b68ad614e2 100644 --- a/features/createroom/impl/build.gradle.kts +++ b/features/createroom/impl/build.gradle.kts @@ -57,6 +57,7 @@ dependencies { testImplementation(libs.test.turbine) testImplementation(projects.libraries.matrix.test) testImplementation(projects.features.selectusers.impl) + testImplementation(projects.features.selectusers.test) androidTestImplementation(libs.test.junitext) diff --git a/features/createroom/impl/src/test/kotlin/io/element/android/features/createroom/impl/addpeople/AddPeoplePresenterTests.kt b/features/createroom/impl/src/test/kotlin/io/element/android/features/createroom/impl/addpeople/AddPeoplePresenterTests.kt index d9f40c1dbf..caf1544a8f 100644 --- a/features/createroom/impl/src/test/kotlin/io/element/android/features/createroom/impl/addpeople/AddPeoplePresenterTests.kt +++ b/features/createroom/impl/src/test/kotlin/io/element/android/features/createroom/impl/addpeople/AddPeoplePresenterTests.kt @@ -22,8 +22,7 @@ import app.cash.molecule.RecompositionClock import app.cash.molecule.moleculeFlow import app.cash.turbine.test import com.google.common.truth.Truth.assertThat -import io.element.android.features.selectusers.api.SelectUsersPresenterArgs -import io.element.android.features.selectusers.impl.DefaultSelectUsersPresenter +import io.element.android.features.selectusers.test.FakeSelectUserPresenterFactory import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import org.junit.Before @@ -35,10 +34,7 @@ class AddPeoplePresenterTests { @Before fun setup() { - val selectUsersFactory = object : DefaultSelectUsersPresenter.DefaultSelectUsersFactory { - override fun create(args: SelectUsersPresenterArgs) = DefaultSelectUsersPresenter(args) - } - presenter = AddPeoplePresenter(selectUsersFactory) + presenter = AddPeoplePresenter(FakeSelectUserPresenterFactory()) } @Test diff --git a/features/createroom/impl/src/test/kotlin/io/element/android/features/createroom/impl/root/CreateRoomRootPresenterTests.kt b/features/createroom/impl/src/test/kotlin/io/element/android/features/createroom/impl/root/CreateRoomRootPresenterTests.kt index 6853fed3d8..28f4668033 100644 --- a/features/createroom/impl/src/test/kotlin/io/element/android/features/createroom/impl/root/CreateRoomRootPresenterTests.kt +++ b/features/createroom/impl/src/test/kotlin/io/element/android/features/createroom/impl/root/CreateRoomRootPresenterTests.kt @@ -18,15 +18,14 @@ package io.element.android.features.createroom.impl.root -import androidx.compose.runtime.Composable import app.cash.molecule.RecompositionClock import app.cash.molecule.moleculeFlow import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.features.selectusers.api.SelectUsersPresenter import io.element.android.features.selectusers.api.SelectUsersPresenterArgs -import io.element.android.features.selectusers.api.SelectUsersState import io.element.android.features.selectusers.api.aSelectUsersState +import io.element.android.features.selectusers.test.FakeSelectUserPresenter import io.element.android.libraries.architecture.Async import io.element.android.libraries.matrix.api.core.RoomId import io.element.android.libraries.matrix.api.core.UserId @@ -155,18 +154,4 @@ class CreateRoomRootPresenterTests { assertThat(stateAfterRetryStartDM.startDmAction.dataOrNull()).isEqualTo(createDmResult.getOrNull()) } } - - private class FakeSelectUserPresenter : SelectUsersPresenter { - - private var state = aSelectUsersState() - - fun givenState(state: SelectUsersState) { - this.state = state - } - - @Composable - override fun present(): SelectUsersState { - return state - } - } } diff --git a/features/selectusers/test/build.gradle.kts b/features/selectusers/test/build.gradle.kts new file mode 100644 index 0000000000..fb4e505709 --- /dev/null +++ b/features/selectusers/test/build.gradle.kts @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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. + */ + +plugins { + id("io.element.android-compose-library") +} + +android { + namespace = "io.element.android.features.selectusers.test" +} + +dependencies { + implementation(projects.libraries.architecture) + implementation(projects.features.selectusers.api) +} diff --git a/features/selectusers/test/src/main/kotlin/io/element/android/features/selectusers/test/FakeSelectUserPresenter.kt b/features/selectusers/test/src/main/kotlin/io/element/android/features/selectusers/test/FakeSelectUserPresenter.kt new file mode 100644 index 0000000000..e92c99df92 --- /dev/null +++ b/features/selectusers/test/src/main/kotlin/io/element/android/features/selectusers/test/FakeSelectUserPresenter.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 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 io.element.android.features.selectusers.test + +import androidx.compose.runtime.Composable +import io.element.android.features.selectusers.api.SelectUsersPresenter +import io.element.android.features.selectusers.api.SelectUsersState +import io.element.android.features.selectusers.api.aSelectUsersState + +class FakeSelectUserPresenter : SelectUsersPresenter { + + private var state = aSelectUsersState() + + fun givenState(state: SelectUsersState) { + this.state = state + } + + @Composable + override fun present(): SelectUsersState { + return state + } +} diff --git a/features/selectusers/test/src/main/kotlin/io/element/android/features/selectusers/test/FakeSelectUserPresenterFactory.kt b/features/selectusers/test/src/main/kotlin/io/element/android/features/selectusers/test/FakeSelectUserPresenterFactory.kt new file mode 100644 index 0000000000..7bf74370c9 --- /dev/null +++ b/features/selectusers/test/src/main/kotlin/io/element/android/features/selectusers/test/FakeSelectUserPresenterFactory.kt @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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 io.element.android.features.selectusers.test + +import io.element.android.features.selectusers.api.SelectUsersPresenter +import io.element.android.features.selectusers.api.SelectUsersPresenterArgs + +class FakeSelectUserPresenterFactory : SelectUsersPresenter.Factory { + + override fun create(args: SelectUsersPresenterArgs): SelectUsersPresenter = FakeSelectUserPresenter() +}