From 2ef9a244cfe09356eba9a77e7c8375eb5b56fd82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20G=C3=B6ransson?= Date: Tue, 21 Nov 2023 11:16:54 +0100 Subject: [PATCH] Add value class assertion test --- .../net/mullvad/mullvadvpn/model/Providers.kt | 5 ++++- .../mullvadvpn/lib/payment/PaymentProvider.kt | 2 +- .../test/arch/classes/ValueClassTests.kt | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/classes/ValueClassTests.kt diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/Providers.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/Providers.kt index 5d97588ca63b..d3c6aacba98e 100644 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/Providers.kt +++ b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/Providers.kt @@ -3,4 +3,7 @@ package net.mullvad.mullvadvpn.model import android.os.Parcelable import kotlinx.parcelize.Parcelize -@JvmInline @Parcelize value class Providers(val providers: HashSet) : Parcelable +@Suppress("ensure value classes property is named value") +@JvmInline +@Parcelize +value class Providers(val providers: HashSet) : Parcelable diff --git a/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/PaymentProvider.kt b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/PaymentProvider.kt index 431b406dc0a0..1d2b3f20b8fb 100644 --- a/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/PaymentProvider.kt +++ b/android/lib/payment/src/main/kotlin/net/mullvad/mullvadvpn/lib/payment/PaymentProvider.kt @@ -1,3 +1,3 @@ package net.mullvad.mullvadvpn.lib.payment -@JvmInline value class PaymentProvider(val paymentRepository: PaymentRepository?) +data class PaymentProvider(val paymentRepository: PaymentRepository?) diff --git a/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/classes/ValueClassTests.kt b/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/classes/ValueClassTests.kt new file mode 100644 index 000000000000..6b40e051e868 --- /dev/null +++ b/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/classes/ValueClassTests.kt @@ -0,0 +1,18 @@ +package net.mullvad.mullvadvpn.test.arch.classes + +import com.lemonappdev.konsist.api.Konsist +import com.lemonappdev.konsist.api.ext.list.modifierprovider.withValueModifier +import com.lemonappdev.konsist.api.ext.list.properties +import com.lemonappdev.konsist.api.verify.assertTrue +import org.junit.Test + +class ValueClassTests { + @Test + fun `ensure value classes property is named value`() { + Konsist.scopeFromProject().classes(includeNested = true).withValueModifier().assertTrue { + it.properties(includeNested = false, includeLocal = false).firstOrNull { property -> + property.name == "value" + } != null + } + } +}