|
@@ -24,12 +24,16 @@ package com.dmdirc.util.io;
|
24
|
24
|
|
25
|
25
|
import java.io.Closeable;
|
26
|
26
|
import java.io.IOException;
|
|
27
|
+import java.io.InputStream;
|
27
|
28
|
|
|
29
|
+import org.junit.Rule;
|
28
|
30
|
import org.junit.Test;
|
|
31
|
+import org.junit.rules.ExpectedException;
|
29
|
32
|
import org.junit.runner.RunWith;
|
30
|
33
|
import org.mockito.Mock;
|
31
|
34
|
import org.mockito.runners.MockitoJUnitRunner;
|
32
|
35
|
|
|
36
|
+import static org.junit.Assert.assertEquals;
|
33
|
37
|
import static org.mockito.Mockito.doThrow;
|
34
|
38
|
import static org.mockito.Mockito.verify;
|
35
|
39
|
|
|
@@ -37,6 +41,7 @@ import static org.mockito.Mockito.verify;
|
37
|
41
|
@RunWith(MockitoJUnitRunner.class)
|
38
|
42
|
public class StreamUtilsTest {
|
39
|
43
|
|
|
44
|
+ @Rule public ExpectedException thrown = ExpectedException.none();
|
40
|
45
|
@Mock private Closeable closeable;
|
41
|
46
|
|
42
|
47
|
@Test
|
|
@@ -45,6 +50,17 @@ public class StreamUtilsTest {
|
45
|
50
|
StreamUtils.close(null);
|
46
|
51
|
}
|
47
|
52
|
|
|
53
|
+ @Test
|
|
54
|
+ public void testReadStream() throws Exception {
|
|
55
|
+ final InputStream inputStream = getClass().getResource("test5.txt").openStream();
|
|
56
|
+ StreamUtils.readStream(inputStream);
|
|
57
|
+ inputStream.close();
|
|
58
|
+ thrown.expect(IOException.class);
|
|
59
|
+ thrown.expectMessage("Stream closed");
|
|
60
|
+ final int result = inputStream.read();
|
|
61
|
+ assertEquals(-1, result);
|
|
62
|
+ }
|
|
63
|
+
|
48
|
64
|
@Test
|
49
|
65
|
public void testCloseWithIoException() throws IOException {
|
50
|
66
|
doThrow(new IOException("Oops")).when(closeable).close();
|