Browse Source

Merge pull request #49 from greboid/dev2

Add a horrible unit test for StreamUtils.
pull/51/head
Chris Smith 9 years ago
parent
commit
cf24cd5232
2 changed files with 17 additions and 1 deletions
  1. 1
    1
      build.gradle
  2. 16
    0
      test/com/dmdirc/util/io/StreamUtilsTest.java

+ 1
- 1
build.gradle View File

@@ -30,7 +30,7 @@ dependencies {
30 30
     compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.0'
31 31
 
32 32
     testCompile group: 'junit', name: 'junit', version: '4.12'
33
-    testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.17'
33
+    testCompile group: 'org.mockito', name: 'mockito-core', version: '1.10.17'
34 34
     testCompile group: 'com.google.jimfs', name: 'jimfs', version: '1.0'
35 35
 }
36 36
 

+ 16
- 0
test/com/dmdirc/util/io/StreamUtilsTest.java View File

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

Loading…
Cancel
Save