clear trace content on test tear down
This commit is contained in:
parent
526c744e75
commit
b147d3898d
|
@ -1,19 +1,19 @@
|
|||
package sealedClassesExercise2
|
||||
|
||||
import atomictest.trace
|
||||
import org.junit.Test
|
||||
import util.loadFileFacade
|
||||
import util.loadMainFunction
|
||||
import util.loadClass
|
||||
import util.loadTraceContent
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class TestSealedClassesExercise2 {
|
||||
|
||||
private val packageName = "sealedClassesExercise2"
|
||||
|
||||
@Test
|
||||
fun `#01 main iterates through sealed subclasses of transport`() {
|
||||
val mainMethod = loadMainFunction(loadFileFacade(packageName))
|
||||
mainMethod.invoke(null)
|
||||
loadClass("sealedClassesExercise1", "Transport")
|
||||
.sealedSubclasses
|
||||
.map { it.simpleName }
|
||||
.forEach { trace(it) }
|
||||
|
||||
assertEquals(
|
||||
message = "Incorrect result of main() invocation",
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import org.junit.After
|
||||
import org.junit.Assert
|
||||
import org.junit.runner.JUnitCore
|
||||
import util.loadTraceContent
|
||||
import util.resetTraceContent
|
||||
import util.runAndCheckSystemOutput
|
||||
import java.io.File
|
||||
import kotlin.reflect.KClass
|
||||
|
@ -12,6 +15,11 @@ abstract class AbstractTestExercises {
|
|||
Assert.assertTrue(result.wasSuccessful())
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
resetTraceContent()
|
||||
}
|
||||
|
||||
protected fun testOutput(outputFileName: String, main: () -> Unit) {
|
||||
val expected = File(outputFileName).readText()
|
||||
runAndCheckSystemOutput("Wrong output", expected, main)
|
||||
|
|
|
@ -43,6 +43,14 @@ fun loadTraceContent(): List<String> {
|
|||
.let { it.call() as List<String> }
|
||||
}
|
||||
|
||||
fun resetTraceContent() {
|
||||
trace::class.members
|
||||
.first { it.name == "trc" }
|
||||
.apply { isAccessible = true }
|
||||
.let { it.call() as MutableList<String> }
|
||||
.apply { clear() }
|
||||
}
|
||||
|
||||
inline fun runAndCheckSystemOutput(message: String, expectedOutput: String, action: () -> Unit) {
|
||||
val actual = runAndGetSystemOutput(action)
|
||||
checkSystemOutput(message, expectedOutput, actual)
|
||||
|
|
Loading…
Reference in New Issue