forked from scribejava/scribejava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamUtilsTest.java
More file actions
49 lines (41 loc) · 1.57 KB
/
Copy pathStreamUtilsTest.java
File metadata and controls
49 lines (41 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.github.scribejava.core.utils;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import org.junit.Test;
import org.junit.function.ThrowingRunnable;
public class StreamUtilsTest {
private static final InputStream ALLWAYS_ERROR_INPUT_STREAM = new AllwaysErrorInputStream();
private static class AllwaysErrorInputStream extends InputStream {
@Override
public int read() throws IOException {
throw new IOException();
}
}
@Test
public void shouldCorrectlyDecodeAStream() throws IOException {
final String value = "expected";
final InputStream is = new ByteArrayInputStream(value.getBytes());
final String decoded = StreamUtils.getStreamContents(is);
assertEquals("expected", decoded);
}
public void shouldFailForNullParameter() throws IOException {
assertThrows(IllegalArgumentException.class, new ThrowingRunnable() {
@Override
public void run() throws Throwable {
StreamUtils.getStreamContents(null);
}
});
}
public void shouldFailWithBrokenStream() throws IOException {
assertThrows(IOException.class, new ThrowingRunnable() {
@Override
public void run() throws Throwable {
// This object simulates problems with input stream.
StreamUtils.getStreamContents(ALLWAYS_ERROR_INPUT_STREAM);
}
});
}
}