Convert stream tests to kotlin
This commit is contained in:
parent
0f34d25e12
commit
f2599821e6
|
@ -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 ?: ""
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Unit>("Exception thrown too early")
|
||||
}
|
||||
|
||||
assertThrows(UncheckedIOException::class.java) { parser.nextSExpression() }
|
||||
assertThrows(LispIOException::class.java) { parser.nextSExpression() }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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() }
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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() }
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue