diff --git a/src/main/kotlin/stream/UncheckedIOException.kt b/src/main/kotlin/stream/LispIOException.kt similarity index 62% rename from src/main/kotlin/stream/UncheckedIOException.kt rename to src/main/kotlin/stream/LispIOException.kt index edf8da0..1ad647c 100644 --- a/src/main/kotlin/stream/UncheckedIOException.kt +++ b/src/main/kotlin/stream/LispIOException.kt @@ -4,7 +4,7 @@ import error.CriticalLispException import java.io.IOException -class UncheckedIOException(private val exception: IOException) : CriticalLispException() { +class LispIOException(private val exception: IOException) : CriticalLispException() { override val message: String get() = exception.message ?: "" diff --git a/src/main/kotlin/stream/SafeInputStream.kt b/src/main/kotlin/stream/SafeInputStream.kt index 5e1f49d..b28441f 100644 --- a/src/main/kotlin/stream/SafeInputStream.kt +++ b/src/main/kotlin/stream/SafeInputStream.kt @@ -14,7 +14,7 @@ class SafeInputStream(underlyingStream: InputStream) { try { return underlyingStream.read() } catch (e: IOException) { - throw UncheckedIOException(e) + throw LispIOException(e) } } @@ -22,7 +22,7 @@ class SafeInputStream(underlyingStream: InputStream) { try { underlyingStream.close() } catch (e: IOException) { - throw UncheckedIOException(e) + throw LispIOException(e) } } } \ No newline at end of file diff --git a/src/main/kotlin/stream/SafeOutputStream.kt b/src/main/kotlin/stream/SafeOutputStream.kt index 93692fe..b1a6be4 100644 --- a/src/main/kotlin/stream/SafeOutputStream.kt +++ b/src/main/kotlin/stream/SafeOutputStream.kt @@ -9,7 +9,7 @@ class SafeOutputStream(private val underlyingStream: OutputStream) { try { underlyingStream.write(b) } catch (e: IOException) { - throw UncheckedIOException(e) + throw LispIOException(e) } } @@ -17,7 +17,7 @@ class SafeOutputStream(private val underlyingStream: OutputStream) { try { underlyingStream.flush() } catch (e: IOException) { - throw UncheckedIOException(e) + throw LispIOException(e) } } @@ -25,7 +25,7 @@ class SafeOutputStream(private val underlyingStream: OutputStream) { try { underlyingStream.close() } catch (e: IOException) { - throw UncheckedIOException(e) + throw LispIOException(e) } } } \ No newline at end of file diff --git a/src/main/kotlin/terminal/TerminalConfiguration.java b/src/main/kotlin/terminal/TerminalConfiguration.java index c6173f6..b7512db 100644 --- a/src/main/kotlin/terminal/TerminalConfiguration.java +++ b/src/main/kotlin/terminal/TerminalConfiguration.java @@ -1,7 +1,7 @@ package terminal; import com.googlecode.lanterna.terminal.IOSafeTerminal; -import stream.UncheckedIOException; +import stream.LispIOException; import java.io.IOException; import java.io.PipedInputStream; @@ -25,7 +25,7 @@ public class TerminalConfiguration { try { inputWriter.connect(inputReader); } catch (IOException e) { - throw new UncheckedIOException(e); + throw new LispIOException(e); } } @@ -39,7 +39,7 @@ public class TerminalConfiguration { try { outputWriter.connect(outputReader); } catch (IOException e) { - throw new UncheckedIOException(e); + throw new LispIOException(e); } } diff --git a/src/test/kotlin/parser/LispParserTest.kt b/src/test/kotlin/parser/LispParserTest.kt index c55d684..5ddc279 100644 --- a/src/test/kotlin/parser/LispParserTest.kt +++ b/src/test/kotlin/parser/LispParserTest.kt @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS import scanner.LispScanner.UnterminatedStringException -import stream.UncheckedIOException +import stream.LispIOException import testutil.TestUtilities.assertIsErrorWithMessage import testutil.TestUtilities.createIOExceptionThrowingInputStream import testutil.TestUtilities.createInputStreamFromString @@ -298,7 +298,7 @@ class LispParserTest { fail("Exception thrown too early") } - assertThrows(UncheckedIOException::class.java) { parser.nextSExpression() } + assertThrows(LispIOException::class.java) { parser.nextSExpression() } } @Test diff --git a/src/test/kotlin/scanner/LispCommentRemovingInputStreamTest.java b/src/test/kotlin/scanner/LispCommentRemovingInputStreamTest.java index abf3c05..874ff76 100644 --- a/src/test/kotlin/scanner/LispCommentRemovingInputStreamTest.java +++ b/src/test/kotlin/scanner/LispCommentRemovingInputStreamTest.java @@ -2,7 +2,7 @@ package scanner; import org.junit.Test; import scanner.LispInputStream.MaximumUnreadsExceededException; -import stream.UncheckedIOException; +import stream.LispIOException; import java.io.InputStream; @@ -195,7 +195,7 @@ public class LispCommentRemovingInputStreamTest { } } - @Test(expected = UncheckedIOException.class) + @Test(expected = LispIOException.class) public void underlyingInputStreamThrowsIOException_ConvertsToUncheckedIOException() { InputStream ioExceptionThrowingInputStream = createIOExceptionThrowingInputStream(); LispInputStream lispInputStream = new LispCommentRemovingInputStream(ioExceptionThrowingInputStream); @@ -210,7 +210,7 @@ public class LispCommentRemovingInputStreamTest { try { lispInputStream.read(); - } catch (UncheckedIOException e) { + } catch (LispIOException e) { String message = e.getMessage(); assertNotNull(message); assertTrue(message.length() >= 0); diff --git a/src/test/kotlin/stream/SafeInputStreamTest.java b/src/test/kotlin/stream/SafeInputStreamTest.java deleted file mode 100644 index ded9b5f..0000000 --- a/src/test/kotlin/stream/SafeInputStreamTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package stream; - -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static testutil.TestUtilities.createIOExceptionThrowingInputStream; -import static testutil.TestUtilities.createInputStreamFromString; - -public class SafeInputStreamTest { - - SafeInputStream safe; - SafeInputStream safeWithException; - - @Before - public void setUp() { - safe = new SafeInputStream(createInputStreamFromString("a")); - safeWithException = new SafeInputStream(createIOExceptionThrowingInputStream()); - } - - @Test - public void readWorks() { - assertEquals('a', (char) safe.read()); - assertEquals(-1, safe.read()); - } - - @Test - public void closeWorks() { - safe.close(); - } - - @Test(expected = UncheckedIOException.class) - public void readThrowsUncheckedException() { - safeWithException.read(); - } - - @Test(expected = UncheckedIOException.class) - public void closeThrowsUncheckedException() { - safeWithException.close(); - } -} diff --git a/src/test/kotlin/stream/SafeInputStreamTest.kt b/src/test/kotlin/stream/SafeInputStreamTest.kt new file mode 100644 index 0000000..d27920e --- /dev/null +++ b/src/test/kotlin/stream/SafeInputStreamTest.kt @@ -0,0 +1,42 @@ +package stream + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Assertions.assertThrows +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import testutil.TestUtilities.createIOExceptionThrowingInputStream +import testutil.TestUtilities.createInputStreamFromString +import util.Characters.EOF + +class SafeInputStreamTest { + + private lateinit var safe: SafeInputStream + private lateinit var safeWithException: SafeInputStream + + @BeforeEach + fun setUp() { + safe = SafeInputStream(createInputStreamFromString("a")) + safeWithException = SafeInputStream(createIOExceptionThrowingInputStream()) + } + + @Test + fun `read works`() { + assertThat(safe.read().toChar()).isEqualTo('a') + assertThat(safe.read()).isEqualTo(EOF) + } + + @Test + fun `close works`() { + safe.close() + } + + @Test + fun `read throws correct exception`() { + assertThrows(LispIOException::class.java) { safeWithException.read() } + } + + @Test + fun `close throws correct exception`() { + assertThrows(LispIOException::class.java) { safeWithException.close() } + } +} diff --git a/src/test/kotlin/stream/SafeOutputStreamTest.java b/src/test/kotlin/stream/SafeOutputStreamTest.java deleted file mode 100644 index 0348cbf..0000000 --- a/src/test/kotlin/stream/SafeOutputStreamTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package stream; - -import org.junit.Before; -import org.junit.Test; - -import java.io.ByteArrayOutputStream; - -import static org.junit.Assert.assertEquals; -import static testutil.TestUtilities.createIOExceptionThrowingOutputStream; - -public class SafeOutputStreamTest { - - SafeOutputStream safe; - SafeOutputStream safeWithException; - ByteArrayOutputStream output; - - @Before - public void setUp() { - output = new ByteArrayOutputStream(); - safe = new SafeOutputStream(output); - safeWithException = new SafeOutputStream(createIOExceptionThrowingOutputStream()); - } - - @Test - public void writeWorks() { - safe.write("write".getBytes()); - assertEquals("write", output.toString()); - } - - @Test - public void flushWorks() { - safe.flush(); - } - - @Test - public void closeWorks() { - safe.close(); - } - - @Test(expected = UncheckedIOException.class) - public void writeThrowsUncheckedException() { - safeWithException.write("write".getBytes()); - } - - @Test(expected = UncheckedIOException.class) - public void flushThrowsUncheckedException() { - safeWithException.flush(); - } - - @Test(expected = UncheckedIOException.class) - public void closeThrowsUncheckedException() { - safeWithException.close(); - } -} diff --git a/src/test/kotlin/stream/SafeOutputStreamTest.kt b/src/test/kotlin/stream/SafeOutputStreamTest.kt new file mode 100644 index 0000000..1f840da --- /dev/null +++ b/src/test/kotlin/stream/SafeOutputStreamTest.kt @@ -0,0 +1,53 @@ +package stream + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Assertions.assertThrows +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import testutil.TestUtilities.createIOExceptionThrowingOutputStream +import java.io.ByteArrayOutputStream + +class SafeOutputStreamTest { + + private lateinit var safe: SafeOutputStream + private lateinit var safeWithException: SafeOutputStream + private lateinit var output: ByteArrayOutputStream + + @BeforeEach + fun setUp() { + output = ByteArrayOutputStream() + safe = SafeOutputStream(output) + safeWithException = SafeOutputStream(createIOExceptionThrowingOutputStream()) + } + + @Test + fun `write works`() { + safe.write("write".toByteArray()) + assertThat(output.toString()).isEqualTo("write") + } + + @Test + fun `flush works`() { + safe.flush() + } + + @Test + fun `close works`() { + safe.close() + } + + @Test + fun `write throws correct exception`() { + assertThrows(LispIOException::class.java) { safeWithException.write("write".toByteArray()) } + } + + @Test + fun `flush throws correct exception`() { + assertThrows(LispIOException::class.java) { safeWithException.flush() } + } + + @Test + fun `close throws correct exception`() { + assertThrows(LispIOException::class.java) { safeWithException.close() } + } +} diff --git a/src/test/kotlin/terminal/TerminalConfigurationTest.java b/src/test/kotlin/terminal/TerminalConfigurationTest.java index 729d9fd..77bdc3b 100644 --- a/src/test/kotlin/terminal/TerminalConfigurationTest.java +++ b/src/test/kotlin/terminal/TerminalConfigurationTest.java @@ -2,7 +2,7 @@ package terminal; import org.junit.Before; import org.junit.Test; -import stream.UncheckedIOException; +import stream.LispIOException; import java.io.IOException; import java.io.PipedInputStream; @@ -27,12 +27,12 @@ public class TerminalConfigurationTest { configuration = new TerminalConfiguration(); } - @Test(expected = UncheckedIOException.class) + @Test(expected = LispIOException.class) public void setInputPairThrowsUncheckedException() { configuration.setInputPair(createIOExceptionThrowingPipedOutputStream(), new PipedInputStream()); } - @Test(expected = UncheckedIOException.class) + @Test(expected = LispIOException.class) public void setOutputPairThrowsUncheckedException() { configuration.setOutputPair(createIOExceptionThrowingPipedOutputStream(), new PipedInputStream()); } diff --git a/src/test/kotlin/terminal/VirtualTerminalInteractor.java b/src/test/kotlin/terminal/VirtualTerminalInteractor.java index 498842e..ef932ad 100644 --- a/src/test/kotlin/terminal/VirtualTerminalInteractor.java +++ b/src/test/kotlin/terminal/VirtualTerminalInteractor.java @@ -6,7 +6,7 @@ import com.googlecode.lanterna.input.KeyStroke; import com.googlecode.lanterna.input.KeyType; import com.googlecode.lanterna.terminal.virtual.DefaultVirtualTerminal; import com.googlecode.lanterna.terminal.virtual.VirtualTerminal; -import stream.UncheckedIOException; +import stream.LispIOException; import java.io.IOException; import java.io.PipedInputStream; @@ -61,7 +61,7 @@ public class VirtualTerminalInteractor { lispTerminal.stop(); outputWriter.close(); } catch (IOException e) { - throw new UncheckedIOException(e); + throw new LispIOException(e); } }