Skip to content

Commit d0375ce

Browse files
committed
tests for #799
1 parent a905e5e commit d0375ce

3 files changed

Lines changed: 125 additions & 0 deletions

File tree

src/functionalTest/groovy/com/autonomousapps/android/AnnotationProcessorSpec.groovy

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,38 @@ final class AnnotationProcessorSpec extends AbstractAndroidSpec {
197197
where:
198198
[gradleVersion, agpVersion] << gradleAgpMatrix()
199199
}
200+
201+
def "kotlin parcelize is redundant when Parcelize annotation is unused (#gradleVersion AGP #agpVersion)"() {
202+
given:
203+
def project = new KotlinParcelizeIsRedundantProject(agpVersion)
204+
androidProject = project.newProject()
205+
206+
when:
207+
build(gradleVersion, androidProject, 'buildHealth')
208+
209+
then:
210+
def actualAdvice = androidProject.adviceFor(project.appSpec)
211+
def expectedAdvice = project.expectedAdvice
212+
assertThat(actualAdvice).containsExactlyElementsIn(expectedAdvice)
213+
214+
where:
215+
[gradleVersion, agpVersion] << gradleAgpMatrix()
216+
}
217+
218+
def "kotlin parcelize is not redundant when Parcelize annotation is used (#gradleVersion AGP #agpVersion)"() {
219+
given:
220+
def project = new KotlinParcelizeIsNotRedundantProject(agpVersion)
221+
androidProject = project.newProject()
222+
223+
when:
224+
build(gradleVersion, androidProject, 'buildHealth')
225+
226+
then:
227+
def actualAdvice = androidProject.adviceFor(project.appSpec)
228+
def expectedAdvice = project.expectedAdvice
229+
assertThat(actualAdvice).containsExactlyElementsIn(expectedAdvice)
230+
231+
where:
232+
[gradleVersion, agpVersion] << gradleAgpMatrix()
233+
}
200234
}

src/functionalTest/kotlin/com/autonomousapps/fixtures/annotationProcessorProjects.kt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,89 @@ class KaptIsRedundantWithUnusedProcsProject(agpVersion: String) {
319319
val expectedAdvice = setOf(PluginAdvice.redundantKapt())
320320
}
321321

322+
class KotlinParcelizeIsNotRedundantProject(agpVersion: String) {
323+
324+
fun newProject() = AndroidProject(
325+
rootSpec = rootSpec,
326+
appSpec = appSpec
327+
)
328+
329+
val rootSpec = RootSpec(agpVersion = agpVersion)
330+
331+
private val sources = mapOf(
332+
"Thing.kt" to """
333+
package $DEFAULT_PACKAGE_NAME
334+
335+
import android.os.Parcelable
336+
import kotlinx.parcelize.Parcelize
337+
338+
@Parcelize
339+
data class Thing(val id: String) : Parcelable
340+
""".trimIndent()
341+
)
342+
343+
val appSpec = AppSpec(
344+
plugins = setOf("kotlin-parcelize"),
345+
sources = sources,
346+
dependencies = listOf(
347+
"implementation" to "org.jetbrains.kotlin:kotlin-stdlib:${Plugin.KOTLIN_VERSION}",
348+
"implementation" to APPCOMPAT
349+
)
350+
)
351+
352+
val expectedAdvice = emptySet<PluginAdvice>()
353+
}
354+
355+
class KotlinParcelizeIsRedundantProject(agpVersion: String) {
356+
357+
fun newProject() = AndroidProject(
358+
rootSpec = rootSpec,
359+
appSpec = appSpec
360+
)
361+
362+
val rootSpec = RootSpec(agpVersion = agpVersion)
363+
364+
private val sources = mapOf(
365+
"Thing.kt" to """
366+
package $DEFAULT_PACKAGE_NAME
367+
368+
import android.os.Parcel
369+
import android.os.Parcelable
370+
371+
data class Thing(val id: String) : Parcelable {
372+
constructor(parcel: Parcel) : this(parcel.readString()!!)
373+
374+
override fun describeContents() = 0
375+
376+
override fun writeToParcel(dest: Parcel, flags: Int) {
377+
dest.writeString(id)
378+
}
379+
380+
companion object CREATOR : Parcelable.Creator<Thing> {
381+
override fun createFromParcel(parcel: Parcel): Thing {
382+
return Thing(parcel)
383+
}
384+
385+
override fun newArray(size: Int): Array<Thing?> {
386+
return arrayOfNulls(size)
387+
}
388+
}
389+
}
390+
""".trimIndent()
391+
)
392+
393+
val appSpec = AppSpec(
394+
plugins = setOf("kotlin-parcelize"),
395+
sources = sources,
396+
dependencies = listOf(
397+
"implementation" to "org.jetbrains.kotlin:kotlin-stdlib:${Plugin.KOTLIN_VERSION}",
398+
"implementation" to APPCOMPAT
399+
)
400+
)
401+
402+
val expectedAdvice = setOf(PluginAdvice.redundantKotlinParcelize())
403+
}
404+
322405
private val transitiveDagger = ModuleCoordinates("com.google.dagger:dagger", "2.24", GradleVariantIdentification(emptySet(), emptyMap()))
323406
private val transitiveInject = ModuleCoordinates("javax.inject:javax.inject", "1", GradleVariantIdentification(emptySet(), emptyMap()))
324407
private val transitiveInject2 = ModuleCoordinates("javax.inject:javax.inject", "1", GradleVariantIdentification(emptySet(), emptyMap()))

src/main/kotlin/com/autonomousapps/advice/PluginAdvice.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ data class PluginAdvice(
1313
const val JAVA_LIBRARY = "java-library"
1414
const val KOTLIN_JVM = "org.jetbrains.kotlin.jvm"
1515
const val KOTLIN_KAPT = "kotlin-kapt"
16+
const val KOTLIN_PARCELIZE = "kotlin-parcelize"
1617

1718
@JvmStatic
1819
fun redundantJavaLibrary() = PluginAdvice(
@@ -34,6 +35,13 @@ data class PluginAdvice(
3435
reason = "this project has the kotlin-kapt (org.jetbrains.kotlin.kapt) plugin applied, but " +
3536
"there are no used annotation processors."
3637
)
38+
39+
@JvmStatic
40+
fun redundantKotlinParcelize() = PluginAdvice(
41+
redundantPlugin = KOTLIN_PARCELIZE,
42+
reason = "this project has the kotlin-parcelize (org.jetbrains.kotlin.plugin.parcelize) plugin applied, but " +
43+
"there are no classes annotated with @Parcelize."
44+
)
3745
}
3846

3947
override fun compareTo(other: PluginAdvice): Int {

0 commit comments

Comments
 (0)