transcendental-lisp/src/test/kotlin/stream/SafeInputStreamTest.java
2018-03-23 18:12:47 -04:00

42 lines
1.0 KiB
Java

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();
}
}