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
42 lines (34 loc) · 1.37 KB
/
Copy pathStreamUtilsTest.java
File metadata and controls
42 lines (34 loc) · 1.37 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
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.fail;
import org.junit.Test;
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);
}
@Test(expected = IllegalArgumentException.class)
public void shouldFailForNullParameter() throws IOException {
StreamUtils.getStreamContents(null);
fail("Must throw exception before getting here");
}
@Test(expected = IOException.class)
public void shouldFailWithBrokenStream() throws IOException {
// This object simulates problems with input stream.
StreamUtils.getStreamContents(ALLWAYS_ERROR_INPUT_STREAM);
fail("Must throw exception before getting here");
}
}