Skip to content

Commit

Permalink
Merge pull request #30 from Open-MBEE/feat/test-coverage-setup
Browse files Browse the repository at this point in the history
JaCoCo setup and initial test function
  • Loading branch information
blake-regalia authored Nov 15, 2023
2 parents 9acb5e0 + 9ffb844 commit e507fd9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
18 changes: 18 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ val kotlinx_json_version: String by project
plugins {
application
kotlin("jvm") version "1.9.20"
jacoco
}

group = "org.openmbee.flexo.mms"
Expand Down Expand Up @@ -40,4 +41,21 @@ dependencies {

testImplementation("io.ktor:ktor-server-tests:$ktor_version")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")

val junitVersion = "5.10.1"
testImplementation("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
}

tasks {
test {
useJUnitPlatform()
}
}

tasks.test {
finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run
}

tasks.jacocoTestReport {
dependsOn(tasks.test) // tests are required to run before generating the report
}
4 changes: 2 additions & 2 deletions src/main/kotlin/org/openmbee/flexo/mms/auth/LdapDetails.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ private fun ldapEscapeImpl(string: String, firstIndex: Int): String = buildStrin
append(string, lastIndex, string.length)
}

private val ESCAPE_CHARACTERS = charArrayOf(' ', '"', '#', '+', ',', ';', '<', '=', '>', '\\')
internal val ESCAPE_CHARACTERS = charArrayOf(' ', '"', '#', '+', ',', ';', '<', '=', '>', '\\')

private fun Char.shouldEscape(): Boolean = this.code.let { codepoint ->
internal fun Char.shouldEscape(): Boolean = this.code.let { codepoint ->
when (codepoint) {
in 0x3f..0x7e -> codepoint == 0x5c // the only forbidden character is backslash
in 0x2d..0x3a -> false // minus, point, slash (allowed), digits + colon :
Expand Down
18 changes: 0 additions & 18 deletions src/test/kotlin/org/openmbee/flexo/mms/ApplicationTest.kt

This file was deleted.

15 changes: 15 additions & 0 deletions src/test/kotlin/org/openmbee/flexo/mms/CharExtensionsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.openmbee.flexo.mms

import kotlin.test.assertTrue
import org.junit.jupiter.api.Test
import org.openmbee.flexo.mms.auth.shouldEscape
import org.openmbee.flexo.mms.auth.ESCAPE_CHARACTERS

class CharExtensionsTest {
@Test
fun testShouldEscape() {
ESCAPE_CHARACTERS.forEach { char ->
assertTrue(char.shouldEscape() as Boolean)
}
}
}

0 comments on commit e507fd9

Please sign in to comment.