|
@@ -26,22 +26,22 @@ import java.io.Closeable;
|
26
|
26
|
import java.io.IOException;
|
27
|
27
|
import java.io.InputStream;
|
28
|
28
|
|
|
29
|
+import org.junit.Rule;
|
29
|
30
|
import org.junit.Test;
|
|
31
|
+import org.junit.rules.ExpectedException;
|
30
|
32
|
import org.junit.runner.RunWith;
|
31
|
33
|
import org.mockito.Mock;
|
32
|
34
|
import org.mockito.runners.MockitoJUnitRunner;
|
33
|
35
|
|
34
|
|
-import static org.mockito.Matchers.any;
|
35
|
|
-import static org.mockito.Matchers.anyInt;
|
36
|
|
-import static org.mockito.Mockito.atLeastOnce;
|
|
36
|
+import static org.junit.Assert.assertEquals;
|
37
|
37
|
import static org.mockito.Mockito.doThrow;
|
38
|
|
-import static org.mockito.Mockito.spy;
|
39
|
38
|
import static org.mockito.Mockito.verify;
|
40
|
39
|
|
41
|
40
|
@SuppressWarnings("resource")
|
42
|
41
|
@RunWith(MockitoJUnitRunner.class)
|
43
|
42
|
public class StreamUtilsTest {
|
44
|
43
|
|
|
44
|
+ @Rule public ExpectedException thrown = ExpectedException.none();
|
45
|
45
|
@Mock private Closeable closeable;
|
46
|
46
|
|
47
|
47
|
@Test
|
|
@@ -52,9 +52,13 @@ public class StreamUtilsTest {
|
52
|
52
|
|
53
|
53
|
@Test
|
54
|
54
|
public void testReadStream() throws Exception {
|
55
|
|
- final InputStream inputStream = spy(getClass().getResource("test5.txt").openStream());
|
|
55
|
+ final InputStream inputStream = getClass().getResource("test5.txt").openStream();
|
56
|
56
|
StreamUtils.readStream(inputStream);
|
57
|
|
- verify(inputStream, atLeastOnce()).read(any(byte[].class), anyInt(), anyInt());
|
|
57
|
+ inputStream.close();
|
|
58
|
+ thrown.expect(IOException.class);
|
|
59
|
+ thrown.expectMessage("Stream closed");
|
|
60
|
+ final int result = inputStream.read();
|
|
61
|
+ assertEquals(-1, result);
|
58
|
62
|
}
|
59
|
63
|
|
60
|
64
|
@Test
|