transcendental-lisp/test/stream/SafeInputStreamTest.java

44 lines
991 B
Java

package stream;
import static org.junit.Assert.assertEquals;
import static testutil.TestUtilities.*;
import org.junit.*;
public class SafeInputStreamTest {
SafeInputStream safe;
SafeInputStream safeWithException;
@Before
public void setUp() throws Exception {
safe = new SafeInputStream(createInputStreamFromString("a"));
safeWithException = new SafeInputStream(createIOExceptionThrowingInputStream());
}
@After
public void tearDown() throws Exception {}
@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();
}
}