1
2
3
4
5
6
7 package com.diasparsoftware.gsbase.test;
8
9 import java.io.*;
10
11 import junit.framework.TestCase;
12
13 import com.diasparsoftware.gsbase.StreamUtil;
14 import com.gargoylesoftware.base.util.DetailedNullPointerException;
15
16 public class GetContentAsStringTest extends TestCase {
17 public void testNull() throws Exception {
18 try {
19 StreamUtil.getContentAsString(null);
20 fail("Allowed null parameter");
21 }
22 catch (DetailedNullPointerException expected) {
23
24 }
25 }
26
27 public void testEmptyStream() throws Exception {
28 InputStream emptyStream = new ByteArrayInputStream(
29 new byte[0]);
30 assertEquals("", StreamUtil
31 .getContentAsString(emptyStream));
32 }
33
34 public void testHappyPath() throws Exception {
35 InputStream happyPathStream = new ByteArrayInputStream(
36 "Happy path".getBytes("ISO-8859-1"));
37 assertEquals("Happy path", StreamUtil
38 .getContentAsString(happyPathStream));
39 }
40
41 }