All Downloads are FREE. Search and download functionalities are using the official Maven repository.

application.test.ColorPrinter.kt Maven / Gradle / Ivy

There is a newer version: 1.3.39
Show newest version
package application.test

import org.fusesource.jansi.Ansi
import org.junit.platform.engine.TestExecutionResult
import org.junit.platform.launcher.TestIdentifier

class ColorPrinter: ContractExecutionPrinter {
    override fun printFinalSummary(testSummary: TestSummary) {
        val (_, partialSuccesses, aborted) = testSummary

        val color = when {
            aborted > 0 -> Ansi.ansi().fgBrightRed()
            partialSuccesses > 0 -> Ansi.ansi().fgYellow()
            else -> Ansi.ansi().fgGreen()
        }

        println(color.a(testSummary.message).reset())
        println()
        println("Executed at ${currentDateAndTime()}")
    }

    override fun printTestSummary(testIdentifier: TestIdentifier?, testExecutionResult: TestExecutionResult?) {
        val color: Ansi = when(testExecutionResult?.status) {
            TestExecutionResult.Status.SUCCESSFUL -> Ansi.ansi().fgGreen()
            TestExecutionResult.Status.ABORTED -> Ansi.ansi().fgYellow()
            TestExecutionResult.Status.FAILED -> Ansi.ansi().fgBrightRed()
            else -> Ansi.ansi()
        }

        println(color.a(testStatusMessage(testIdentifier, testExecutionResult)).reset())
    }

    override fun printFailureTitle(failures: String) {
        println(failures)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy