Skip to content

Commit

Permalink
Merge pull request #1750 from Adyen/chore/konsist
Browse files Browse the repository at this point in the history
Add Konsist test to verify if applicable classes have internal visibility
  • Loading branch information
OscarSpruit authored Aug 15, 2024
2 parents 7bcee7d + c7a6eb9 commit a6724f0
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 40 deletions.
12 changes: 0 additions & 12 deletions card/api/card.api
Original file line number Diff line number Diff line change
Expand Up @@ -638,15 +638,3 @@ public final class com/adyen/checkout/card/internal/ui/view/SecurityCodeInput :
public final class com/adyen/checkout/card/internal/ui/view/SecurityCodeInput$Companion {
}

public final class com/adyen/checkout/card/internal/util/CardNumberValidation : java/lang/Enum {
public static final field INVALID_ILLEGAL_CHARACTERS Lcom/adyen/checkout/card/internal/util/CardNumberValidation;
public static final field INVALID_LUHN_CHECK Lcom/adyen/checkout/card/internal/util/CardNumberValidation;
public static final field INVALID_TOO_LONG Lcom/adyen/checkout/card/internal/util/CardNumberValidation;
public static final field INVALID_TOO_SHORT Lcom/adyen/checkout/card/internal/util/CardNumberValidation;
public static final field INVALID_UNSUPPORTED_BRAND Lcom/adyen/checkout/card/internal/util/CardNumberValidation;
public static final field VALID Lcom/adyen/checkout/card/internal/util/CardNumberValidation;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/adyen/checkout/card/internal/util/CardNumberValidation;
public static fun values ()[Lcom/adyen/checkout/card/internal/util/CardNumberValidation;
}

Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ object CardValidationUtils {
}
}

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
enum class CardNumberValidation {
VALID,
INVALID_ILLEGAL_CHARACTERS,
Expand Down
2 changes: 2 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ ext {
json_version = '20240303'
jose4j_version = '0.9.6'
junit_jupiter_version = "5.10.3"
konsist_version = "0.15.1"
mockito_kotlin_version = "5.4.0"
mockito_version = "5.12.0"
robolectric_version = "4.13"
Expand Down Expand Up @@ -165,6 +166,7 @@ ext {
"org.junit.jupiter:junit-jupiter-params:$junit_jupiter_version",
"org.junit.vintage:junit-vintage-engine:$junit_jupiter_version",
],
konsist : "com.lemonappdev:konsist:$konsist_version",
kotlinCoroutines: [
"org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version",
"app.cash.turbine:turbine:$turbine_version"
Expand Down
7 changes: 0 additions & 7 deletions drop-in/api/drop-in.api
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,6 @@ public abstract class com/adyen/checkout/dropin/internal/service/BaseDropInServi
public final class com/adyen/checkout/dropin/internal/service/BaseDropInService$Companion {
}

public final class com/adyen/checkout/dropin/internal/ui/ActionComponentFragmentEvent : java/lang/Enum {
public static final field HANDLE_ACTION Lcom/adyen/checkout/dropin/internal/ui/ActionComponentFragmentEvent;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/adyen/checkout/dropin/internal/ui/ActionComponentFragmentEvent;
public static fun values ()[Lcom/adyen/checkout/dropin/internal/ui/ActionComponentFragmentEvent;
}

public final class com/adyen/checkout/dropin/internal/ui/model/DropInPaymentMethodInformation$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/adyen/checkout/dropin/internal/ui/model/DropInPaymentMethodInformation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ internal class ActionComponentViewModel(
}
}

enum class ActionComponentFragmentEvent {
internal enum class ActionComponentFragmentEvent {
HANDLE_ACTION
}
2 changes: 2 additions & 0 deletions example-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ dependencies {
// Tests
testImplementation testLibraries.junit5
testImplementation testLibraries.mockito
testImplementation testLibraries.konsist


androidTestImplementation testLibraries.androidTest
androidTestImplementation testLibraries.barista
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2024 Adyen N.V.
*
* This file is open source and available under the MIT license. See the LICENSE file for more info.
*
* Created by oscars on 7/8/2024.
*/

package com.adyen.checkout.example

import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.annotation.RestrictTo
import androidx.appcompat.widget.AppCompatImageView
import androidx.constraintlayout.widget.ConstraintLayout
import com.google.android.material.textfield.TextInputEditText
import com.lemonappdev.konsist.api.Konsist
import com.lemonappdev.konsist.api.ext.list.modifierprovider.withoutAbstractModifier
import com.lemonappdev.konsist.api.ext.list.withPackage
import com.lemonappdev.konsist.api.ext.list.withoutAllConstructors
import com.lemonappdev.konsist.api.ext.list.withoutExternalParentOf
import com.lemonappdev.konsist.api.verify.assertTrue
import org.junit.jupiter.api.Test

internal class ClassVisibilityTest {

@Test
fun `when class is in internal package, then visibility should be internal`() {
Konsist
.scopeFromProduction()
.classes(includeNested = false)
.withPackage("..internal..")
// Exclude abstract classes because @RestrictTo carries over to their children.
.withoutAbstractModifier()
// Exclude Views because they have to be public to be used in XML.
.withoutExternalParentOf(
AppCompatImageView::class,
ConstraintLayout::class,
LinearLayout::class,
TextInputEditText::class,
ViewGroup::class,
indirectParents = true,
)
// Exclude classes that are exposed publicly but can only be instantiated internally (like ComponentProviders).
.withoutAllConstructors {
it.hasInternalModifier || it.hasPrivateModifier || it.hasAnnotationOf(RestrictTo::class)
}
.assertTrue {
it.hasInternalModifier || it.hasPrivateModifier || it.hasAnnotationOf(RestrictTo::class)
}
}
}
24 changes: 24 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8298,6 +8298,14 @@
<sha256 value="a75c709e660357e6a60a4a88e5d9bf510107e5327627369bc1f8030f398938d1" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.lemonappdev" name="konsist" version="0.15.1">
<artifact name="konsist-0.15.1.jar">
<sha256 value="14fe23bf92f4ed2f736e253bbbc61c3615234196f2e8e2968ada430b6e85d239" origin="Generated by Gradle"/>
</artifact>
<artifact name="konsist-0.15.1.module">
<sha256 value="4ceff4efc7e1425bb2fc03ef4de3d8cdcb2370e1cee9c8377757238db04fe667" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.pinterest.ktlint" name="ktlint-cli" version="1.0.1">
<artifact name="ktlint-cli-1.0.1.jar">
<sha256 value="81889a9cab5da042aea48869b170299fec7d6f66773aa7d5245b8b8ccb8d0c89" origin="Generated by Gradle"/>
Expand Down Expand Up @@ -12185,6 +12193,14 @@
<sha256 value="012e1c55ed6ade417bcb824112ebea682ad625dfbee16085c379ccfa14faf033" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlin" name="kotlin-stdlib-jdk7" version="1.9.23">
<artifact name="kotlin-stdlib-jdk7-1.9.23.jar">
<sha256 value="34b1dff7ee4e42af452dca1e3c001e352bcd9e9ec27dfdd478bb7e76e7bfa3e1" origin="Generated by Gradle"/>
</artifact>
<artifact name="kotlin-stdlib-jdk7-1.9.23.pom">
<sha256 value="b89b57a2bbf0778b040d0e41c0c9b185198932c77ee84dd66a34609b3cf3e5a0" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlin" name="kotlin-stdlib-jdk8" version="1.5.21">
<artifact name="kotlin-stdlib-jdk8-1.5.21.pom">
<sha256 value="82c652994c02ee3cf27a6d9661a99a6d2b084a4a9722a07f3abaecaadb3357a1" origin="Generated by Gradle"/>
Expand Down Expand Up @@ -12272,6 +12288,14 @@
<sha256 value="a3b07deb091f2aed59d6559884f44f99cff5df9b9fa35a24bcd6b8b069cff48d" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlin" name="kotlin-stdlib-jdk8" version="1.9.23">
<artifact name="kotlin-stdlib-jdk8-1.9.23.jar">
<sha256 value="d624c60cc1b472a1dcbee3ad1ec4ea95f2fba0032152ddb15905c6207f7718ec" origin="Generated by Gradle"/>
</artifact>
<artifact name="kotlin-stdlib-jdk8-1.9.23.pom">
<sha256 value="682c0a9e78435b5c5a613131b720cf83ada056e036f14d6663734632012574ff" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlin" name="kotlin-tooling-core" version="1.9.22">
<artifact name="kotlin-tooling-core-1.9.22.jar">
<sha256 value="8938eb97e36320daa3e6fb2a60fd2a05b232ff4a557173c5019f045b8832d9f4" origin="Generated by Gradle"/>
Expand Down
20 changes: 0 additions & 20 deletions ui-core/api/ui-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ public final class com/adyen/checkout/ui/core/internal/data/model/AddressItem$Cr
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/adyen/checkout/ui/core/internal/exception/PermissionRequestException : com/adyen/checkout/core/exception/CheckoutException {
public fun <init> (Ljava/lang/String;)V
}

public final class com/adyen/checkout/ui/core/internal/ui/AddressFormUIState$Companion {
public final fun fromAddressParams (Lcom/adyen/checkout/ui/core/internal/ui/model/AddressParams;)Lcom/adyen/checkout/ui/core/internal/ui/AddressFormUIState;
}
Expand Down Expand Up @@ -275,22 +271,6 @@ public abstract interface class com/adyen/checkout/ui/core/internal/ui/view/Adye
public abstract fun onTextChanged (Landroid/text/Editable;)V
}

public final class com/adyen/checkout/ui/core/internal/ui/view/LookupOption {
public fun <init> (Lcom/adyen/checkout/components/core/LookupAddress;Z)V
public synthetic fun <init> (Lcom/adyen/checkout/components/core/LookupAddress;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Lcom/adyen/checkout/components/core/LookupAddress;
public final fun component2 ()Z
public final fun copy (Lcom/adyen/checkout/components/core/LookupAddress;Z)Lcom/adyen/checkout/ui/core/internal/ui/view/LookupOption;
public static synthetic fun copy$default (Lcom/adyen/checkout/ui/core/internal/ui/view/LookupOption;Lcom/adyen/checkout/components/core/LookupAddress;ZILjava/lang/Object;)Lcom/adyen/checkout/ui/core/internal/ui/view/LookupOption;
public fun equals (Ljava/lang/Object;)Z
public final fun getLookupAddress ()Lcom/adyen/checkout/components/core/LookupAddress;
public final fun getSubtitle ()Ljava/lang/String;
public final fun getTitle ()Ljava/lang/String;
public fun hashCode ()I
public final fun isLoading ()Z
public fun toString ()Ljava/lang/String;
}

public final class com/adyen/checkout/ui/core/internal/ui/view/PaymentInProgressView : androidx/constraintlayout/widget/ConstraintLayout, com/adyen/checkout/ui/core/internal/ui/ComponentView {
public fun getView ()Landroid/view/View;
public fun highlightValidationErrors ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

package com.adyen.checkout.ui.core.internal.exception

import androidx.annotation.RestrictTo
import com.adyen.checkout.core.exception.CheckoutException

/**
* Exception thrown when requested runtime permission is denied.
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
class PermissionRequestException(errorMessage: String) : CheckoutException(errorMessage)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package com.adyen.checkout.ui.core.internal.ui.view

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.annotation.RestrictTo
import androidx.core.view.isVisible
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
Expand Down Expand Up @@ -56,6 +57,7 @@ internal class AddressLookupOptionsAdapter(
}
}

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
data class LookupOption(
val lookupAddress: LookupAddress,
val isLoading: Boolean = false
Expand Down

0 comments on commit a6724f0

Please sign in to comment.