Skip to content

Commit

Permalink
✅ Update tests of KotoolsSamplesJvmPlugin.apply method
Browse files Browse the repository at this point in the history
  • Loading branch information
LVMVRQUXL committed Sep 17, 2024
1 parent f881112 commit 98567b0
Showing 1 changed file with 22 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,10 @@ class KotoolsSamplesJvmPluginTest {

@Test
fun `apply should create 'sample' Kotlin source set`() {
val project: Project = ProjectBuilder.builder()
.build()
project.pluginManager.apply("org.jetbrains.kotlin.jvm")
val plugin = KotoolsSamplesJvmPlugin()
project.pluginManager.apply(plugin::class)
val project: Project = this.validProject
val kotlin: KotlinJvmProjectExtension = project.extensions.getByType()
val sample: KotlinSourceSet? = kotlin.sourceSets.findByName("sample")
val plugin = KotoolsSamplesJvmPlugin()
assertNotNull(
actual = sample,
message = "$plugin should create 'sample' source set"
Expand All @@ -98,40 +95,29 @@ class KotoolsSamplesJvmPluginTest {

@Test
fun `apply should configure 'main' Kotlin source set`() {
val project: Project = ProjectBuilder.builder()
.build()
project.pluginManager.apply("org.jetbrains.kotlin.jvm")
project.pluginManager.apply(KotoolsSamplesJvmPlugin::class)
val kotlin: KotlinJvmProjectExtension = project.extensions.getByType()
val kotlin: KotlinJvmProjectExtension =
this.validProject.extensions.getByType()
val main: KotlinSourceSet = kotlin.sourceSets.getByName("main")
val sample: KotlinSourceSet = kotlin.sourceSets.getByName("sample")
assertTrue(
actual = main in sample.dependsOn,
message = "$sample should depend on $main"
)
val actual: Boolean = main in sample.dependsOn
val message = "$sample should depend on $main"
assertTrue(actual, message)
}

@Test
fun `apply should configure 'test' Kotlin source set`() {
val project: Project = ProjectBuilder.builder()
.build()
project.pluginManager.apply("org.jetbrains.kotlin.jvm")
project.pluginManager.apply(KotoolsSamplesJvmPlugin::class)
val kotlin: KotlinJvmProjectExtension = project.extensions.getByType()
val kotlin: KotlinJvmProjectExtension =
this.validProject.extensions.getByType()
val sample: KotlinSourceSet = kotlin.sourceSets.getByName("sample")
val test: KotlinSourceSet = kotlin.sourceSets.getByName("test")
assertTrue(
actual = sample in test.dependsOn,
message = "$test should depend on $sample"
)
val actual: Boolean = sample in test.dependsOn
val message = "$test should depend on $sample"
assertTrue(actual, message)
}

@Test
fun `apply should configure 'test' Java source set`() {
val project: Project = ProjectBuilder.builder()
.build()
project.pluginManager.apply("org.jetbrains.kotlin.jvm")
project.pluginManager.apply(KotoolsSamplesJvmPlugin::class)
val project: Project = this.validProject
val test: SourceSet = project.extensions
.getByType<JavaPluginExtension>()
.sourceSets
Expand All @@ -144,6 +130,15 @@ class KotoolsSamplesJvmPluginTest {
assertTrue(actual, message)
}

private val validProject: Project
get() {
val project: Project = ProjectBuilder.builder()
.build()
project.pluginManager.apply("org.jetbrains.kotlin.jvm")
project.pluginManager.apply(KotoolsSamplesJvmPlugin::class)
return project
}

// ------------------------------ Conversions ------------------------------

@Test
Expand Down

0 comments on commit 98567b0

Please sign in to comment.