[KPM] Implement test to check if data classes are marked as internal
KT-51262 KT-51220
This commit is contained in:
committed by
Space
parent
fa13e38e91
commit
21d6c11bbb
+8
@@ -8,3 +8,11 @@ package org.jetbrains.kotlin.gradle.kpm.idea
|
|||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
interface IdeaKotlinFragmentDependency : Serializable
|
interface IdeaKotlinFragmentDependency : Serializable
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
@InternalKotlinGradlePluginApi
|
||||||
|
class IdeaKotlinFragmentDependencyImpl: IdeaKotlinFragmentDependency {
|
||||||
|
companion object {
|
||||||
|
const val serialVersionUID = 0L
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+24
-5
@@ -11,6 +11,8 @@ import org.reflections.Reflections
|
|||||||
import java.lang.reflect.Field
|
import java.lang.reflect.Field
|
||||||
import java.lang.reflect.Modifier
|
import java.lang.reflect.Modifier
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
import kotlin.reflect.KVisibility
|
||||||
|
import kotlin.reflect.KVisibility.PUBLIC
|
||||||
import kotlin.reflect.full.memberProperties
|
import kotlin.reflect.full.memberProperties
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
@@ -21,6 +23,8 @@ import kotlin.test.assertTrue
|
|||||||
@RunWith(Parameterized::class)
|
@RunWith(Parameterized::class)
|
||||||
class IdeaKotlinProjectModelObjectGraphTest(private val node: KClass<*>, @Suppress("unused_parameter") clazzName: String) {
|
class IdeaKotlinProjectModelObjectGraphTest(private val node: KClass<*>, @Suppress("unused_parameter") clazzName: String) {
|
||||||
|
|
||||||
|
private val reflections = Reflections("org.jetbrains.kotlin")
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test - node implements Serializable`() {
|
fun `test - node implements Serializable`() {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
@@ -31,12 +35,27 @@ class IdeaKotlinProjectModelObjectGraphTest(private val node: KClass<*>, @Suppre
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test - node implementations contain serialVersionUID`() {
|
fun `test - node implementations contain serialVersionUID`() {
|
||||||
val reflections = Reflections("org.jetbrains.kotlin")
|
val implementations = reflections.getSubTypesOf(node.java).plus(node.java)
|
||||||
reflections.getSubTypesOf(node.java).forEach { subtype ->
|
.filter { subtype -> !subtype.isInterface && !Modifier.isAbstract(subtype.modifiers) }
|
||||||
if (!subtype.isInterface && !Modifier.isAbstract(subtype.modifiers)) {
|
|
||||||
assertNodeImplementationDefinesSerialVersionUID(subtype)
|
assertTrue(
|
||||||
|
implementations.isNotEmpty(),
|
||||||
|
"No implementations found for $node"
|
||||||
|
)
|
||||||
|
|
||||||
|
implementations.forEach { implementation -> assertNodeImplementationDefinesSerialVersionUID(implementation) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test - node implementations are marked with InternalKotlinGradlePluginApi when data class`() {
|
||||||
|
reflections.getSubTypesOf(node.java).plus(node.java)
|
||||||
|
.filter { subtype -> subtype.kotlin.isData && subtype.kotlin.visibility == PUBLIC }
|
||||||
|
.forEach { dataClass ->
|
||||||
|
assertTrue(
|
||||||
|
dataClass.annotations.any { it.annotationClass.simpleName == "InternalKotlinGradlePluginApi" },
|
||||||
|
"Expected $dataClass to be annotated with '@InternalKotlinGradlePluginApi'"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun assertNodeImplementationDefinesSerialVersionUID(implementationClass: Class<*>) {
|
private fun assertNodeImplementationDefinesSerialVersionUID(implementationClass: Class<*>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user