Skip to content

Commit

Permalink
Converted tests to JUnit and upgraded Truth Version
Browse files Browse the repository at this point in the history
  • Loading branch information
handstandsam committed Jun 7, 2024
1 parent 3b4897b commit 20b02b4
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 185 deletions.
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ktor = "2.3.11"
vanniktech-maven-publish = "0.28.0"
jetbrains-compose = "1.6.10"
ksp = "1.9.23-1.0.20"
truth = "1.4.2"

[libraries]
anvil-annotations = { module = "com.squareup.anvil:annotations", version.ref = "anvil" }
Expand All @@ -33,7 +34,7 @@ ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "kto
ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor" }
ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }

truth = { module = "com.google.truth:truth", version.ref = "truth" }


#### Kotlin analysis ####
Expand Down
11 changes: 2 additions & 9 deletions owners/owners-github-codeowners/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@ dependencies {
implementation(libs.kotlin.compiler.embeddable)
implementation(project(":invert-models"))
implementation(project(":invert-gradle-plugin"))
testImplementation(libs.kotlin.test)

testImplementation("com.google.truth:truth:1.0.1")
val junit5 = "5.3.1"
testImplementation("org.junit.jupiter:junit-jupiter-api:$junit5")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junit5")
val spek = "2.0.7"
testImplementation("org.spekframework.spek2:spek-dsl-jvm:$spek")
testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:$spek")
testImplementation(kotlin("reflect"))
testImplementation(libs.truth)
testImplementation(libs.kotlin.test)
}
Original file line number Diff line number Diff line change
@@ -1,56 +1,52 @@
package com.github.pgreze.kowners

import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertFails
import kotlin.test.assertNull

class CodeOwnershipTest : Spek({
class CodeOwnershipTest {

describe("Codeowners comment") {
it("returns null") {
assertNull("# A comment".parseCodeOwnersLine())
}
@Test
fun `Codeowners comment`() {
assertNull("# A comment".parseCodeOwnersLine())
}

describe("Empty Codeowners line") {
it("returns null") {
assertNull("".parseCodeOwnersLine())
}
@Test
fun `Empty Codeowners line`() {
assertNull("".parseCodeOwnersLine())
}

describe("Simple Codeowners line") {
it("returns correct value for 1 owner") {
val expected = CodeOwnership(
pattern = Pattern("docs/"),
owners = listOf("@me")
)
assertEquals(expected, "docs/ @me".parseCodeOwnersLine())
}

it("returns correct value for multiple owners") {
val expected = CodeOwnership(
pattern = Pattern("docs/"),
owners = listOf("@me", "@org/team-name")
)
assertEquals(expected, "docs/ @me @org/team-name".parseCodeOwnersLine())
}
@Test
fun `Simple Codeowners line - returns correct value for 1 owner`() {
val expected = CodeOwnership(
pattern = Pattern("docs/"),
owners = listOf("@me")
)
assertEquals(expected, "docs/ @me".parseCodeOwnersLine())
}

describe("Codeowners line with escaped space") {
it("returns correct value") {
val expected = CodeOwnership(
pattern = Pattern("docs/\\ hello"),
owners = listOf("@me")
)
assertEquals(expected, "docs/\\ hello @me".parseCodeOwnersLine())
}
@Test
fun `Simple Codeowners line - returns correct value for multiple owners`() {
val expected = CodeOwnership(
pattern = Pattern("docs/"),
owners = listOf("@me", "@org/team-name")
)
assertEquals(expected, "docs/ @me @org/team-name".parseCodeOwnersLine())
}

describe("Codeowners line with invalid owners") {
it("returns correct message for no owner") {
assertFails("No owner in line: docs/") { "docs/".parseCodeOwnersLine() }
}
@Test
fun `Codeowners line with escaped space - returns correct value`() {
val expected = CodeOwnership(
pattern = Pattern("docs/\\ hello"),
owners = listOf("@me")
)
assertEquals(expected, "docs/\\ hello @me".parseCodeOwnersLine())
}
})

@Test
fun `Codeowners line with invalid owners returns correct message for no owner`() {
assertFails("No owner in line: docs/") { "docs/".parseCodeOwnersLine() }
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.github.pgreze.kowners

import com.google.common.truth.Truth.assertThat
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import org.junit.Test

class OwnersResolverTest : Spek({
class OwnersResolverTest {

describe("docs/sample project") {
@Test
fun `docs-sample project`() {
val ownersResolver = CODEOWNERS.split("\n")
.filter(String::isNotEmpty)
.parseCodeOwners()
Expand All @@ -16,11 +16,9 @@ class OwnersResolverTest : Spek({
.map { it to ownersResolver.resolveOwnership(it) }
.toMap()

it("resolve all owners") {
assertThat(fileToOwners).isEqualTo(FILE_TO_OWNER)
}
assertThat(fileToOwners).isEqualTo(FILE_TO_OWNER)
}
})
}

private const val CODEOWNERS = """
*.md charlie
Expand Down
Loading

0 comments on commit 20b02b4

Please sign in to comment.