Skip to content

Commit

Permalink
Replace Spek with Kotlin Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ozsie committed Sep 9, 2024
1 parent 6d2a943 commit 3d78925
Show file tree
Hide file tree
Showing 16 changed files with 470 additions and 588 deletions.
56 changes: 24 additions & 32 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
<plexus-utils.version>3.5.1</plexus-utils.version>

<!-- Test -->
<spek-api.version>1.2.1</spek-api.version>
<mockito-kotlin.version>1.6.0</mockito-kotlin.version>
<junit-platform-surefire-provider.version>1.3.2</junit-platform-surefire-provider.version>

Expand Down Expand Up @@ -113,35 +112,24 @@
</dependency>

<dependency>
<groupId>org.jetbrains.spek</groupId>
<artifactId>spek-api</artifactId>
<version>${spek-api.version}</version>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>${jcommander.version}</version>
</dependency>

<dependency>
<groupId>org.jetbrains.spek</groupId>
<artifactId>spek-junit-platform-engine</artifactId>
<version>${spek-api.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
Expand Down Expand Up @@ -278,7 +266,7 @@
<version>${maven-surefire-plugin.version}</version>
<configuration>
<includes>
<include>**/*Spec.*</include>
<include>**/*Test.*</include>
</includes>
</configuration>
<dependencies>
Expand All @@ -288,15 +276,9 @@
<version>${junit-platform-surefire-provider.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.spek</groupId>
<artifactId>spek-junit-platform-engine</artifactId>
<version>${spek-api.version}</version>
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-runtime</artifactId>
</exclusion>
</exclusions>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
Expand Down Expand Up @@ -375,6 +357,11 @@
<name>JCenter Repository</name>
<url>https://jcenter.bintray.com/</url>
</repository>
<repository>
<id>maven</id>
<name>Maven</name>
<url>https://repo1.maven.org/maven2/</url>
</repository>
</repositories>

<pluginRepositories>
Expand All @@ -383,6 +370,11 @@
<name>JCenter Repository</name>
<url>https://jcenter.bintray.com/</url>
</pluginRepository>
<pluginRepository>
<id>maven</id>
<name>Maven</name>
<url>https://repo1.maven.org/maven2/</url>
</pluginRepository>
</pluginRepositories>

<scm>
Expand Down
93 changes: 0 additions & 93 deletions src/test/java/com/github/ozsie/CheckMojoSpec.kt

This file was deleted.

73 changes: 73 additions & 0 deletions src/test/java/com/github/ozsie/CheckMojoTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.github.ozsie

import io.github.detekt.tooling.api.MaxIssuesReached
import kotlin.test.assertFailsWith
import kotlin.test.expect
import org.junit.jupiter.api.Test

class CheckMojoTest {
private val codeSamplesDirectory = CheckMojoTest::class.java.classLoader.getResource("code-samples")!!.file
private val invalidPackageNamingDirectoryPath = "$codeSamplesDirectory/invalid-package-naming"

@Test
fun `a CheckMojo and 'skip' is true Unit is expected`() {
val checkMojo = CheckMojo()
checkMojo.skip = true
expect(Unit) {
checkMojo.execute()
}
}

@Test
fun `a CheckMojo and 'skip' is false Unit is expected`() {
val checkMojo = CheckMojo()
checkMojo.skip = false
expect(Unit) {
checkMojo.execute()
}
}

@Test
fun `a CheckMojo and 'failBuildOnMaxIssuesReached' is false Unit is exptected`() {
val checkMojo = CheckMojo().apply {
input = invalidPackageNamingDirectoryPath
failBuildOnMaxIssuesReached = false
}
expect(Unit) {
checkMojo.execute()
}
}

@Test
fun `a CheckMojo and 'failBuildOnMaxIssuesReached' is true Unit is exptected`() {
val checkMojo = CheckMojo().apply {
input = invalidPackageNamingDirectoryPath
failBuildOnMaxIssuesReached = true
}
assertFailsWith(MaxIssuesReached::class, "Build failed with 1 weighted issues.") {
checkMojo.execute()
}
}

@Test
fun `multiple valid comma separated input directories are supplied detekt analyses the specified directories`() {
val checkMojo = CheckMojo().apply {
input = "$codeSamplesDirectory/valid,$codeSamplesDirectory/valid2"
failBuildOnMaxIssuesReached = true
}
assertFailsWith(MaxIssuesReached::class, "Build failed with 2 weighted issues.") {
checkMojo.execute()
}
}

@Test
fun `a mix of valid and invalid comma separated input directories are supplied detekt analysis is aborted`() {
val checkMojo = CheckMojo().apply {
input = "$codeSamplesDirectory/valid,invalidDirectory"
failBuildOnMaxIssuesReached = false
}
expect(Unit) {
checkMojo.execute()
}
}
}
90 changes: 0 additions & 90 deletions src/test/java/com/github/ozsie/CheckWithTypeResolutionMojoSpec.kt

This file was deleted.

Loading

0 comments on commit 3d78925

Please sign in to comment.