Skip to content

Commit c9b5676

Browse files
author
Marcel Schnelle
authored
Remove support for com.android.test plugin (#134)
Projects using this plugin only contain instrumented tests, and unit tests are explicitly disblaed. Thus, there is no reason for the JUnit 5 plugin to configure anything
1 parent 96a4b9e commit c9b5676

File tree

2 files changed

+11
-21
lines changed
  • android-junit5-tests/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5
  • android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5

2 files changed

+11
-21
lines changed

android-junit5-tests/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ class PluginSpec : Spek({
4040
describe("a misconfigured project") {
4141
val testProjectBuilder by memoized { factory.newProject(testRoot) }
4242

43-
on("not applying any Android plugin") {
43+
on("not applying any supported Android plugin") {
4444
val expect = throws<PluginApplicationException> { testProjectBuilder.build() }
4545

4646
it("throws an error") {
4747
assertThat(expect.cause?.message)
48-
.isEqualTo("An Android plugin must be applied to this project")
48+
.contains("One of the following plugins must be applied to this project")
4949
}
5050
}
5151

@@ -99,7 +99,7 @@ class PluginSpec : Spek({
9999

100100
it("adds a general-purpose filter to the JUnit 5 extension point") {
101101
val extension = ju5.extensionByName<FiltersExtension>("filters")
102-
assertThat(extension).isNotNull()
102+
assertThat(extension).isNotNull
103103
assertThat(ju5.filters).isEqualTo(extension)
104104
assertThat(ju5.findFilters()).isEqualTo(extension)
105105
assertThat(ju5.findFilters(qualifier = null)).isEqualTo(extension)
@@ -115,7 +115,7 @@ class PluginSpec : Spek({
115115

116116
it("adds a $buildType-specific filter to the JUnit 5 extension point") {
117117
val extension = ju5.extensionByName<FiltersExtension>("${buildType}Filters")
118-
assertThat(extension).isNotNull()
118+
assertThat(extension).isNotNull
119119
assertThat(ju5.findFilters(qualifier = buildType)).isEqualTo(extension)
120120
}
121121
}
@@ -162,7 +162,7 @@ class PluginSpec : Spek({
162162
listOf("free", "paid").forEach { flavor ->
163163
it("adds a $flavor-specific filter to the JUnit 5 extension point") {
164164
val extension = ju5.extensionByName<FiltersExtension>("${flavor}Filters")
165-
assertThat(extension).isNotNull()
165+
assertThat(extension).isNotNull
166166
assertThat(ju5.findFilters(qualifier = flavor)).isEqualTo(extension)
167167
}
168168

@@ -171,7 +171,7 @@ class PluginSpec : Spek({
171171

172172
it("adds a $variantName-specific filter to the JUnit 5 extension point") {
173173
val extension = ju5.extensionByName<FiltersExtension>("${variantName}Filters")
174-
assertThat(extension).isNotNull()
174+
assertThat(extension).isNotNull
175175
assertThat(ju5.findFilters(qualifier = variantName)).isEqualTo(extension)
176176
}
177177
}

android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Configuration.kt

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ import com.android.build.gradle.AppExtension
44
import com.android.build.gradle.BaseExtension
55
import com.android.build.gradle.FeatureExtension
66
import com.android.build.gradle.LibraryExtension
7-
import com.android.build.gradle.TestExtension
87
import com.android.build.gradle.api.ApplicationVariant
98
import com.android.build.gradle.api.BaseVariant
109
import com.android.build.gradle.api.LibraryVariant
11-
import de.mannodermaus.gradle.plugins.junit5.Type.Application
12-
import de.mannodermaus.gradle.plugins.junit5.Type.DynamicFeature
13-
import de.mannodermaus.gradle.plugins.junit5.Type.Feature
14-
import de.mannodermaus.gradle.plugins.junit5.Type.Library
15-
import de.mannodermaus.gradle.plugins.junit5.Type.Test
10+
import de.mannodermaus.gradle.plugins.junit5.Type.*
1611
import de.mannodermaus.gradle.plugins.junit5.internal.android
1712
import de.mannodermaus.gradle.plugins.junit5.internal.hasPlugin
1813
import org.gradle.api.DomainObjectSet
@@ -45,11 +40,6 @@ private sealed class Type<in T : BaseExtension>(val pluginId: String) {
4540
extension.applicationVariants
4641
}
4742

48-
object Test : Type<TestExtension>("com.android.test") {
49-
override fun variants(extension: TestExtension): DomainObjectSet<ApplicationVariant> =
50-
extension.applicationVariants
51-
}
52-
5343
object Library : Type<LibraryExtension>("com.android.library") {
5444
override fun variants(extension: LibraryExtension): DomainObjectSet<LibraryVariant> {
5545
return extension.libraryVariants
@@ -66,12 +56,12 @@ private sealed class Type<in T : BaseExtension>(val pluginId: String) {
6656

6757
object DynamicFeature : Type<AppExtension>("com.android.dynamic-feature") {
6858
override fun variants(extension: AppExtension): DomainObjectSet<ApplicationVariant> =
69-
extension.applicationVariants
59+
extension.applicationVariants
7060
}
7161
}
7262

7363
private val allTypes: List<Type<*>> =
74-
listOf(Application, Test, Library, Feature, DynamicFeature)
64+
listOf(Application, Library, Feature, DynamicFeature)
7565

7666
@Suppress("UNCHECKED_CAST")
7767
private fun findType(project: Project): Type<BaseExtension> {
@@ -80,8 +70,8 @@ private fun findType(project: Project): Type<BaseExtension> {
8070
}
8171

8272
if (type == null) {
83-
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
84-
throw ProjectConfigurationException("An Android plugin must be applied to this project", IllegalArgumentException())
73+
val supportedPluginNames = allTypes.map { it.pluginId }
74+
throw ProjectConfigurationException("One of the following plugins must be applied to this project: $supportedPluginNames", IllegalArgumentException())
8575
} else {
8676
return type as Type<BaseExtension>
8777
}

0 commit comments

Comments
 (0)