Selaa lähdekoodia

Merge pull request #49 from greboid/dev2

Add a horrible unit test for StreamUtils.
pull/51/head
Chris Smith 9 vuotta sitten
vanhempi
commit
cf24cd5232
2 muutettua tiedostoa jossa 17 lisäystä ja 1 poistoa
  1. 1
    1
      build.gradle
  2. 16
    0
      test/com/dmdirc/util/io/StreamUtilsTest.java

+ 1
- 1
build.gradle Näytä tiedosto

30
     compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.0'
30
     compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.0'
31
 
31
 
32
     testCompile group: 'junit', name: 'junit', version: '4.12'
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
     testCompile group: 'com.google.jimfs', name: 'jimfs', version: '1.0'
34
     testCompile group: 'com.google.jimfs', name: 'jimfs', version: '1.0'
35
 }
35
 }
36
 
36
 

+ 16
- 0
test/com/dmdirc/util/io/StreamUtilsTest.java Näytä tiedosto

24
 
24
 
25
 import java.io.Closeable;
25
 import java.io.Closeable;
26
 import java.io.IOException;
26
 import java.io.IOException;
27
+import java.io.InputStream;
27
 
28
 
29
+import org.junit.Rule;
28
 import org.junit.Test;
30
 import org.junit.Test;
31
+import org.junit.rules.ExpectedException;
29
 import org.junit.runner.RunWith;
32
 import org.junit.runner.RunWith;
30
 import org.mockito.Mock;
33
 import org.mockito.Mock;
31
 import org.mockito.runners.MockitoJUnitRunner;
34
 import org.mockito.runners.MockitoJUnitRunner;
32
 
35
 
36
+import static org.junit.Assert.assertEquals;
33
 import static org.mockito.Mockito.doThrow;
37
 import static org.mockito.Mockito.doThrow;
34
 import static org.mockito.Mockito.verify;
38
 import static org.mockito.Mockito.verify;
35
 
39
 
37
 @RunWith(MockitoJUnitRunner.class)
41
 @RunWith(MockitoJUnitRunner.class)
38
 public class StreamUtilsTest {
42
 public class StreamUtilsTest {
39
 
43
 
44
+    @Rule public ExpectedException thrown = ExpectedException.none();
40
     @Mock private Closeable closeable;
45
     @Mock private Closeable closeable;
41
 
46
 
42
     @Test
47
     @Test
45
         StreamUtils.close(null);
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
     @Test
64
     @Test
49
     public void testCloseWithIoException() throws IOException {
65
     public void testCloseWithIoException() throws IOException {
50
         doThrow(new IOException("Oops")).when(closeable).close();
66
         doThrow(new IOException("Oops")).when(closeable).close();

Loading…
Peruuta
Tallenna