From 1b14306a9952c49a0a2ce75cac04f6b9d301b512 Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Sun, 25 Mar 2018 11:34:34 -0400 Subject: [PATCH] Refactor test code --- .../kotlin/environment/RuntimeEnvironmentTest.kt | 16 ++++++++-------- src/test/kotlin/error/ErrorManagerTest.kt | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/kotlin/environment/RuntimeEnvironmentTest.kt b/src/test/kotlin/environment/RuntimeEnvironmentTest.kt index 2e1a398..3aef234 100644 --- a/src/test/kotlin/environment/RuntimeEnvironmentTest.kt +++ b/src/test/kotlin/environment/RuntimeEnvironmentTest.kt @@ -19,11 +19,11 @@ class RuntimeEnvironmentTest { private const val TERMINATED_EXCEPTIONALLY = "TERMINATED_EXCEPTIONALLY" } - private var indicatorSet: MutableSet? = null + private val indicatorSet: MutableSet = HashSet() @BeforeEach fun setUp() { - indicatorSet = HashSet() + indicatorSet.clear() RuntimeEnvironment.reset() } @@ -77,18 +77,18 @@ class RuntimeEnvironmentTest { @Test fun `assign a termination function`() { - RuntimeEnvironment.terminationFunction = Runnable { indicatorSet!!.add(TERMINATED_SUCCESSFULLY) } + RuntimeEnvironment.terminationFunction = Runnable { indicatorSet.add(TERMINATED_SUCCESSFULLY) } RuntimeEnvironment.terminateSuccessfully() - assertThat(indicatorSet!!.contains(TERMINATED_SUCCESSFULLY)).isTrue() + assertThat(indicatorSet.contains(TERMINATED_SUCCESSFULLY)).isTrue() } @Test fun `assign an error termination function`() { - RuntimeEnvironment.errorTerminationFunction = Runnable { indicatorSet!!.add(TERMINATED_EXCEPTIONALLY) } + RuntimeEnvironment.errorTerminationFunction = Runnable { indicatorSet.add(TERMINATED_EXCEPTIONALLY) } RuntimeEnvironment.terminateExceptionally() - assertThat(indicatorSet!!.contains(TERMINATED_EXCEPTIONALLY)).isTrue() + assertThat(indicatorSet.contains(TERMINATED_EXCEPTIONALLY)).isTrue() } @Test @@ -134,8 +134,8 @@ class RuntimeEnvironmentTest { RuntimeEnvironment.errorOutput = System.err RuntimeEnvironment.errorManager = ErrorManager() RuntimeEnvironment.path = "testpath/" - RuntimeEnvironment.terminationFunction = Runnable { indicatorSet!!.add(TERMINATED_SUCCESSFULLY) } - RuntimeEnvironment.errorTerminationFunction = Runnable { indicatorSet!!.add(TERMINATED_EXCEPTIONALLY) } + RuntimeEnvironment.terminationFunction = Runnable { indicatorSet.add(TERMINATED_SUCCESSFULLY) } + RuntimeEnvironment.errorTerminationFunction = Runnable { indicatorSet.add(TERMINATED_EXCEPTIONALLY) } RuntimeEnvironment.promptDecorator = Function { s -> "[$s]" } RuntimeEnvironment.valueOutputDecorator = Function { s -> "($s)" } RuntimeEnvironment.warningOutputDecorator = Function { s -> "|$s|" } diff --git a/src/test/kotlin/error/ErrorManagerTest.kt b/src/test/kotlin/error/ErrorManagerTest.kt index fd48e70..1bd2a98 100644 --- a/src/test/kotlin/error/ErrorManagerTest.kt +++ b/src/test/kotlin/error/ErrorManagerTest.kt @@ -20,9 +20,9 @@ class ErrorManagerTest { private const val MESSAGE = "message" } - private lateinit var indicatorSet: MutableSet - private lateinit var errorOutputStream: ByteArrayOutputStream - private lateinit var outputStream: ByteArrayOutputStream + private val indicatorSet: MutableSet = HashSet() + private val errorOutputStream: ByteArrayOutputStream = ByteArrayOutputStream() + private val outputStream: ByteArrayOutputStream = ByteArrayOutputStream() private fun createErrorManagerWithIndicators(): ErrorManager { RuntimeEnvironment.errorTerminationFunction = Runnable { indicatorSet.add(TERMINATED) } @@ -68,9 +68,9 @@ class ErrorManagerTest { @BeforeEach fun setUp() { - indicatorSet = HashSet() - errorOutputStream = ByteArrayOutputStream() - outputStream = ByteArrayOutputStream() + indicatorSet.clear() + errorOutputStream.reset() + outputStream.reset() RuntimeEnvironment.reset() }