Refactor test code

This commit is contained in:
Mike Cifelli 2018-03-25 11:34:34 -04:00
parent daf43b0ea7
commit 1b14306a99
2 changed files with 14 additions and 14 deletions

View File

@ -19,11 +19,11 @@ class RuntimeEnvironmentTest {
private const val TERMINATED_EXCEPTIONALLY = "TERMINATED_EXCEPTIONALLY" private const val TERMINATED_EXCEPTIONALLY = "TERMINATED_EXCEPTIONALLY"
} }
private var indicatorSet: MutableSet<String>? = null private val indicatorSet: MutableSet<String> = HashSet()
@BeforeEach @BeforeEach
fun setUp() { fun setUp() {
indicatorSet = HashSet() indicatorSet.clear()
RuntimeEnvironment.reset() RuntimeEnvironment.reset()
} }
@ -77,18 +77,18 @@ class RuntimeEnvironmentTest {
@Test @Test
fun `assign a termination function`() { fun `assign a termination function`() {
RuntimeEnvironment.terminationFunction = Runnable { indicatorSet!!.add(TERMINATED_SUCCESSFULLY) } RuntimeEnvironment.terminationFunction = Runnable { indicatorSet.add(TERMINATED_SUCCESSFULLY) }
RuntimeEnvironment.terminateSuccessfully() RuntimeEnvironment.terminateSuccessfully()
assertThat(indicatorSet!!.contains(TERMINATED_SUCCESSFULLY)).isTrue() assertThat(indicatorSet.contains(TERMINATED_SUCCESSFULLY)).isTrue()
} }
@Test @Test
fun `assign an error termination function`() { fun `assign an error termination function`() {
RuntimeEnvironment.errorTerminationFunction = Runnable { indicatorSet!!.add(TERMINATED_EXCEPTIONALLY) } RuntimeEnvironment.errorTerminationFunction = Runnable { indicatorSet.add(TERMINATED_EXCEPTIONALLY) }
RuntimeEnvironment.terminateExceptionally() RuntimeEnvironment.terminateExceptionally()
assertThat(indicatorSet!!.contains(TERMINATED_EXCEPTIONALLY)).isTrue() assertThat(indicatorSet.contains(TERMINATED_EXCEPTIONALLY)).isTrue()
} }
@Test @Test
@ -134,8 +134,8 @@ class RuntimeEnvironmentTest {
RuntimeEnvironment.errorOutput = System.err RuntimeEnvironment.errorOutput = System.err
RuntimeEnvironment.errorManager = ErrorManager() RuntimeEnvironment.errorManager = ErrorManager()
RuntimeEnvironment.path = "testpath/" RuntimeEnvironment.path = "testpath/"
RuntimeEnvironment.terminationFunction = Runnable { indicatorSet!!.add(TERMINATED_SUCCESSFULLY) } RuntimeEnvironment.terminationFunction = Runnable { indicatorSet.add(TERMINATED_SUCCESSFULLY) }
RuntimeEnvironment.errorTerminationFunction = Runnable { indicatorSet!!.add(TERMINATED_EXCEPTIONALLY) } RuntimeEnvironment.errorTerminationFunction = Runnable { indicatorSet.add(TERMINATED_EXCEPTIONALLY) }
RuntimeEnvironment.promptDecorator = Function { s -> "[$s]" } RuntimeEnvironment.promptDecorator = Function { s -> "[$s]" }
RuntimeEnvironment.valueOutputDecorator = Function { s -> "($s)" } RuntimeEnvironment.valueOutputDecorator = Function { s -> "($s)" }
RuntimeEnvironment.warningOutputDecorator = Function { s -> "|$s|" } RuntimeEnvironment.warningOutputDecorator = Function { s -> "|$s|" }

View File

@ -20,9 +20,9 @@ class ErrorManagerTest {
private const val MESSAGE = "message" private const val MESSAGE = "message"
} }
private lateinit var indicatorSet: MutableSet<String> private val indicatorSet: MutableSet<String> = HashSet()
private lateinit var errorOutputStream: ByteArrayOutputStream private val errorOutputStream: ByteArrayOutputStream = ByteArrayOutputStream()
private lateinit var outputStream: ByteArrayOutputStream private val outputStream: ByteArrayOutputStream = ByteArrayOutputStream()
private fun createErrorManagerWithIndicators(): ErrorManager { private fun createErrorManagerWithIndicators(): ErrorManager {
RuntimeEnvironment.errorTerminationFunction = Runnable { indicatorSet.add(TERMINATED) } RuntimeEnvironment.errorTerminationFunction = Runnable { indicatorSet.add(TERMINATED) }
@ -68,9 +68,9 @@ class ErrorManagerTest {
@BeforeEach @BeforeEach
fun setUp() { fun setUp() {
indicatorSet = HashSet() indicatorSet.clear()
errorOutputStream = ByteArrayOutputStream() errorOutputStream.reset()
outputStream = ByteArrayOutputStream() outputStream.reset()
RuntimeEnvironment.reset() RuntimeEnvironment.reset()
} }