2017-03-23 12:14:44 -04:00
|
|
|
package stream;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
2017-11-12 09:42:25 -05:00
|
|
|
import static testutil.TestUtilities.createIOExceptionThrowingInputStream;
|
|
|
|
import static testutil.TestUtilities.createInputStreamFromString;
|
2017-03-23 12:14:44 -04:00
|
|
|
|
2017-11-12 09:42:25 -05:00
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
2017-03-23 12:14:44 -04:00
|
|
|
|
|
|
|
public class SafeInputStreamTest {
|
|
|
|
|
|
|
|
SafeInputStream safe;
|
|
|
|
SafeInputStream safeWithException;
|
|
|
|
|
|
|
|
@Before
|
2017-03-24 09:36:44 -04:00
|
|
|
public void setUp() {
|
2017-03-23 12:14:44 -04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|