Merge pull request #2948 from element-hq/feature/bma/konsistUpgrade

Konsist upgrade
This commit is contained in:
Benoit Marty
2024-05-31 09:18:43 +02:00
committed by GitHub
51 changed files with 66 additions and 45 deletions

View File

@@ -16,6 +16,7 @@
package io.element.android.appnav.room.joined
import androidx.compose.runtime.Immutable
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import io.element.android.libraries.di.SessionScope
import io.element.android.libraries.di.SingleIn
@@ -31,6 +32,7 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import javax.inject.Inject
@Immutable
sealed interface LoadingRoomState {
data object Loading : LoadingRoomState
data object Error : LoadingRoomState

View File

@@ -26,7 +26,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
class AnalyticsVerificationStateMappingTests {
class AnalyticsVerificationStateMappingTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -31,7 +31,7 @@ import io.element.android.services.analytics.test.FakeAnalyticsService
import kotlinx.coroutines.test.runTest
import org.junit.Test
class DefaultStartDMActionTests {
class DefaultStartDMActionTest {
@Test
fun `when dm is found, assert state is updated with given room id`() = runTest {
val matrixClient = FakeMatrixClient().apply {

View File

@@ -30,7 +30,7 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
class AddPeoplePresenterTests {
class AddPeoplePresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -61,7 +61,7 @@ private const val AN_URI_FROM_CAMERA_2 = "content://uri_from_camera_2"
private const val AN_URI_FROM_GALLERY = "content://uri_from_gallery"
@RunWith(RobolectricTestRunner::class)
class ConfigureRoomPresenterTests {
class ConfigureRoomPresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -37,7 +37,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
class CreateRoomRootPresenterTests {
class CreateRoomRootPresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -33,7 +33,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
class DefaultUserListPresenterTests {
class DefaultUserListPresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -37,7 +37,7 @@ import kotlinx.coroutines.cancel
import kotlinx.coroutines.test.runTest
import org.junit.Test
class DefaultFtueServiceTests {
class DefaultFtueServiceTest {
@Test
fun `given any check being false and session verification state being loaded, FtueState is Incomplete`() = runTest {
val sessionVerificationService = FakeSessionVerificationService().apply {

View File

@@ -38,7 +38,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
class NotificationsOptInPresenterTests {
class NotificationsOptInPresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -42,6 +42,7 @@ data class JoinRoomState(
}
}
@Immutable
sealed interface ContentState {
data class Loading(val roomIdOrAlias: RoomIdOrAlias) : ContentState
data class Failure(val roomIdOrAlias: RoomIdOrAlias, val error: Throwable) : ContentState

View File

@@ -16,6 +16,7 @@
package io.element.android.features.messages.impl.attachments.preview
import androidx.compose.runtime.Immutable
import io.element.android.features.messages.impl.attachments.Attachment
data class AttachmentsPreviewState(
@@ -24,8 +25,11 @@ data class AttachmentsPreviewState(
val eventSink: (AttachmentsPreviewEvents) -> Unit
)
@Immutable
sealed interface SendActionState {
data object Idle : SendActionState
@Immutable
sealed interface Sending : SendActionState {
data object Processing : Sending
data class Uploading(val progress: Float) : Sending

View File

@@ -16,8 +16,10 @@
package io.element.android.features.messages.impl.sender
import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
@Immutable
sealed interface SenderNameMode {
data class Timeline(val mainColor: Color) : SenderNameMode
data object Reply : SenderNameMode

View File

@@ -36,7 +36,7 @@ import org.junit.Rule
import org.junit.Test
import java.lang.IllegalStateException
class ForwardMessagesPresenterTests {
class ForwardMessagesPresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -31,7 +31,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
class ReportMessagePresenterTests {
class ReportMessagePresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -28,7 +28,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
class CustomReactionPresenterTests {
class CustomReactionPresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -34,7 +34,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
class ReactionSummaryPresenterTests {
class ReactionSummaryPresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -26,7 +26,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
class ReadReceiptBottomSheetPresenterTests {
class ReadReceiptBottomSheetPresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -28,7 +28,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
class RetrySendMenuPresenterTests {
class RetrySendMenuPresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -33,7 +33,7 @@ import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.test.runTest
import org.junit.Test
class BlockedUsersPresenterTests {
class BlockedUsersPresenterTest {
@Test
fun `present - initial state with no blocked users`() = runTest {
val presenter = aBlockedUsersPresenter()

View File

@@ -36,7 +36,7 @@ import io.element.android.tests.testutils.consumeItemsUntilPredicate
import kotlinx.coroutines.test.runTest
import org.junit.Test
class EditDefaultNotificationSettingsPresenterTests {
class EditDefaultNotificationSettingsPresenterTest {
@Test
fun `present - ensures initial state is correct`() = runTest {
val notificationSettingsService = FakeNotificationSettingsService()

View File

@@ -38,7 +38,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Test
import kotlin.time.Duration.Companion.milliseconds
class NotificationSettingsPresenterTests {
class NotificationSettingsPresenterTest {
@Test
fun `present - ensures initial state is correct`() = runTest {
val presenter = createNotificationSettingsPresenter()

View File

@@ -16,6 +16,7 @@
package io.element.android.features.roomdetails.impl
import androidx.compose.runtime.Immutable
import io.element.android.features.leaveroom.api.LeaveRoomState
import io.element.android.features.userprofile.shared.UserProfileState
import io.element.android.libraries.matrix.api.core.RoomAlias
@@ -45,11 +46,13 @@ data class RoomDetailsState(
val eventSink: (RoomDetailsEvent) -> Unit
)
@Immutable
sealed interface RoomDetailsType {
data object Room : RoomDetailsType
data class Dm(val roomMember: RoomMember) : RoomDetailsType
}
@Immutable
sealed interface RoomTopicState {
data object Hidden : RoomTopicState
data object CanAddTopic : RoomTopicState

View File

@@ -64,7 +64,7 @@ import org.junit.Test
import kotlin.time.Duration.Companion.milliseconds
@ExperimentalCoroutinesApi
class RoomDetailsPresenterTests {
class RoomDetailsPresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -46,7 +46,7 @@ import org.junit.Rule
import org.junit.Test
@ExperimentalCoroutinesApi
class RoomMemberListPresenterTests {
class RoomMemberListPresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -46,7 +46,7 @@ import org.junit.Rule
import org.junit.Test
@ExperimentalCoroutinesApi
class RoomMemberDetailsPresenterTests {
class RoomMemberDetailsPresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -42,7 +42,7 @@ import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runTest
import org.junit.Test
class DefaultRoomMembersModerationPresenterTests {
class DefaultRoomMembersModerationPresenterTest {
@Test
fun `canDisplayModerationActions - when room is DM is false`() = runTest {
val room = FakeMatrixRoom(isDirect = true, isPublic = true, isOneToOne = true).apply {

View File

@@ -33,7 +33,7 @@ import io.element.android.tests.testutils.consumeItemsUntilPredicate
import kotlinx.coroutines.test.runTest
import org.junit.Test
class RoomNotificationSettingsPresenterTests {
class RoomNotificationSettingsPresenterTest {
@Test
fun `present - initial state is created from room info`() = runTest {
val presenter = createRoomNotificationSettingsPresenter()

View File

@@ -36,7 +36,7 @@ import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Test
class RolesAndPermissionPresenterTests {
class RolesAndPermissionPresenterTest {
@Test
fun `present - initial state`() = runTest {
val presenter = createRolesAndPermissionsPresenter()

View File

@@ -43,7 +43,7 @@ import org.junit.runner.RunWith
import org.robolectric.annotation.Config
@RunWith(AndroidJUnit4::class)
class RolesAndPermissionsViewTests {
class RolesAndPermissionsViewTest {
@get:Rule val rule = createAndroidComposeRule<ComponentActivity>()
@Test

View File

@@ -42,7 +42,7 @@ import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runTest
import org.junit.Test
class ChangeRolesPresenterTests {
class ChangeRolesPresenterTest {
@Test
fun `present - initial state`() = runTest {
val presenter = createChangeRolesPresenter()

View File

@@ -39,7 +39,7 @@ import io.element.android.services.analytics.test.FakeAnalyticsService
import kotlinx.coroutines.test.runTest
import org.junit.Test
class ChangeRoomPermissionsPresenterTests {
class ChangeRoomPermissionsPresenterTest {
@Test
fun `present - initial state`() = runTest {
val section = ChangeRoomPermissionsSection.RoomDetails

View File

@@ -46,7 +46,7 @@ import org.junit.rules.TestRule
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class ChangeRoomPermissionsViewTests {
class ChangeRoomPermissionsViewTest {
@get:Rule val rule = createAndroidComposeRule<ComponentActivity>()
@Test

View File

@@ -92,7 +92,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
class RoomListPresenterTests {
class RoomListPresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -29,7 +29,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Test
import io.element.android.libraries.matrix.api.roomlist.RoomListFilter as MatrixRoomListFilter
class RoomListFiltersPresenterTests {
class RoomListFiltersPresenterTest {
@Test
fun `present - initial state`() = runTest {
val presenter = createRoomListFiltersPresenter()

View File

@@ -30,7 +30,7 @@ import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class RoomListFiltersViewTests {
class RoomListFiltersViewTest {
@get:Rule val rule = createAndroidComposeRule<ComponentActivity>()
@Test

View File

@@ -36,7 +36,7 @@ import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runTest
import org.junit.Test
class RoomListSearchPresenterTests {
class RoomListSearchPresenterTest {
@Test
fun `present - initial state`() = runTest {
val presenter = createRoomListSearchPresenter()

View File

@@ -43,7 +43,7 @@ import org.junit.Rule
import org.junit.Test
@ExperimentalCoroutinesApi
class UserProfilePresenterTests {
class UserProfilePresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -42,7 +42,7 @@ import org.junit.Rule
import org.junit.Test
@ExperimentalCoroutinesApi
class VerifySelfSessionPresenterTests {
class VerifySelfSessionPresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -134,7 +134,7 @@ test_arch_core = "androidx.arch.core:core-testing:2.2.0"
test_junit = "junit:junit:4.13.2"
test_runner = "androidx.test:runner:1.5.2"
test_mockk = "io.mockk:mockk:1.13.11"
test_konsist = "com.lemonappdev:konsist:0.13.0"
test_konsist = "com.lemonappdev:konsist:0.15.1"
test_turbine = "app.cash.turbine:turbine:1.1.0"
test_truth = "com.google.truth:truth:1.4.2"
test_parameter_injector = "com.google.testparameterinjector:test-parameter-injector:1.16"

View File

@@ -39,7 +39,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Test
@OptIn(ExperimentalCoroutinesApi::class)
class AsyncIndicatorTests {
class AsyncIndicatorTest {
@Test
fun `initial state`() = runTest {
val state = AsyncIndicatorState()

View File

@@ -21,7 +21,7 @@ import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
import org.junit.Test
class SnackbarDispatcherTests {
class SnackbarDispatcherTest {
@Test
fun `given an empty queue the flow emits a null item`() = runTest {
val snackbarDispatcher = SnackbarDispatcher()

View File

@@ -17,8 +17,10 @@
package io.element.android.libraries.matrix.api.core
import android.os.Parcelable
import androidx.compose.runtime.Immutable
import kotlinx.parcelize.Parcelize
@Immutable
sealed interface RoomIdOrAlias : Parcelable {
@Parcelize
@JvmInline

View File

@@ -24,7 +24,7 @@ import io.element.android.libraries.matrix.test.room.aRoomSummaryFilled
import kotlinx.coroutines.test.runTest
import org.junit.Test
class RoomListFilterTests {
class RoomListFilterTest {
private val regularRoom = aRoomSummaryFilled(
aRoomSummaryDetails(
isDirect = false

View File

@@ -39,7 +39,7 @@ import org.matrix.rustcomponents.sdk.TaskHandle
// NOTE: this class is using a fake implementation of a Rust SDK interface which returns actual Rust objects with pointers.
// Since we don't access the data in those objects, this is fine for our tests, but that's as far as we can test this class.
class RoomSummaryListProcessorTests {
class RoomSummaryListProcessorTest {
private val summaries = MutableStateFlow<List<RoomSummary>>(emptyList())
@Test

View File

@@ -32,7 +32,7 @@ import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class MediaSenderTests {
class MediaSenderTest {
@Test
fun `given an attachment when sending it the preprocessor always runs`() = runTest {
val preProcessor = FakeMediaPreProcessor()

View File

@@ -32,7 +32,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
class RoomSelectPresenterTests {
class RoomSelectPresenterTest {
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -28,7 +28,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
class DatabaseSessionStoreTests {
class DatabaseSessionStoreTest {
private lateinit var database: SessionDatabase
private lateinit var databaseSessionStore: DatabaseSessionStore

View File

@@ -28,7 +28,7 @@ import io.element.android.services.analytics.test.FakeAnalyticsService
import kotlinx.coroutines.test.runTest
import org.junit.Test
class TroubleshootNotificationsPresenterTests {
class TroubleshootNotificationsPresenterTest {
@Test
fun `present - initial state`() = runTest {
val presenter = createTroubleshootNotificationsPresenter()

View File

@@ -87,7 +87,13 @@ class KonsistArchitectureTest {
.withAnnotationOf(Composable::class)
.assertTrue(additionalMessage = "Consider adding the @Immutable or @Stable annotation to the sealed interface") {
it.parameters.all { param ->
param.type.fullyQualifiedName !in forbiddenInterfacesForComposableParameter
val type = param.type.text
return@all if (type.startsWith("@") || type.startsWith("(") || type.startsWith("suspend")) {
true
} else {
val fullyQualifiedName = param.type.declaration.packagee?.fullyQualifiedName + "." + type
fullyQualifiedName !in forbiddenInterfacesForComposableParameter
}
}
}
}

View File

@@ -78,7 +78,7 @@ class KonsistClassNameTest {
.assertTrue {
val interfaceName = it.name.replace("Fake", "")
it.name.startsWith("Fake") &&
it.parents.any { parent -> parent.name.replace(".", "") == interfaceName }
it.parents().any { parent -> parent.name.replace(".", "") == interfaceName }
}
}
}

View File

@@ -27,10 +27,11 @@ import org.junit.Test
class KonsistTestTest {
@Test
fun `Classes name containing @Test must end with 'Test''`() {
fun `Classes name containing @Test must end with 'Test'`() {
Konsist
.scopeFromTest()
.classes()
.withoutName("S", "T")
.withFunction { it.hasAnnotationOf(Test::class) }
.assertTrue { it.name.endsWith("Test") }
}