1 package de.fu_berlin.ties.io;
2
3 import junit.framework.TestCase;
4
5 import java.io.ByteArrayInputStream;
6 import java.io.ByteArrayOutputStream;
7 import java.io.File;
8 import java.io.InputStream;
9 import java.io.OutputStream;
10 import java.io.Reader;
11 import java.io.StringReader;
12 import java.io.StringWriter;
13 import java.io.Writer;
14 import java.net.URL;
15
16
17 /***
18 * Generated by JUnitDoclet, a tool provided by
19 * ObjectFab GmbH under LGPL.
20 * Please see www.junitdoclet.org, www.gnu.org
21 * and www.objectfab.de for informations about
22 * the tool, the licence and the authors.
23 */
24
25
26 public class IOUtilsTest
27
28 extends TestCase
29
30 {
31
32 private static final String testString =
33 "This is just a simple test string without any real value";
34
35
36 public IOUtilsTest(String name) {
37
38 super(name);
39
40 }
41
42 public de.fu_berlin.ties.io.IOUtils createInstance() throws Exception {
43
44 return null;
45
46 }
47
48 protected void setUp() throws Exception {
49
50 super.setUp();
51
52 }
53
54 protected void tearDown() throws Exception {
55
56 super.tearDown();
57
58 }
59
60 public void testCreateOutFile() throws Exception {
61
62
63 }
64
65 public void testDetermineCharset() throws Exception {
66
67
68 }
69
70 public void testDetermineCharsetName() throws Exception {
71
72
73 }
74
75 public void testDetermineOutputDirectory() throws Exception {
76
77
78 }
79
80 public void testGetBaseName() throws Exception {
81
82
83 }
84
85 public void testGetExtension() throws Exception {
86
87 final String[] urls = new String[] {
88 "http://java.sun.com",
89 "http://java.sun.com/",
90 "http://java.sun.com/index.html",
91 "http://java.sun.com/j2ee/index.html",
92 "http://java.sun.com/j2ee/index.html?param1=bla¶m2=blub",
93 "http://java.sun.com/j2ee/index.jsp;sessionXYZ",
94 "http://java.sun.com/j2ee/#section2",
95 "http://java.sun.com/j2ee/file.index.html#section2",
96 };
97 final String[] expectedURLExt = new String[] {
98 "",
99 "",
100 "html",
101 "html",
102 "html",
103 "jsp",
104 "",
105 "html"
106 };
107 URL currentURL;
108
109 for (int i = 0; i < urls.length; i++) {
110 currentURL = new URL(urls[i]);
111 assertEquals(IOUtils.getExtension(currentURL), expectedURLExt[i]);
112 }
113
114 final String[] filenames = new String[] {
115 "README",
116 "docs/README",
117 "/usr/local/share",
118 "README.txt",
119 "docs/readme.html",
120 "C://Windows",
121 "C://Windows//",
122 "C://autoexec.bat",
123 "C://Windows//logo.bmp",
124 "/dir/sub.directory/README",
125 "C://dir//sub.directory//README",
126 "/usr/local/j2sdk1.4.1_01",
127 "jdk1.4",
128 };
129 final String[] expectedFileExt = new String[] {
130 "",
131 "",
132 "",
133 "txt",
134 "html",
135 "",
136 "",
137 "bat",
138 "bmp",
139 "",
140 "",
141 "1_01",
142 "4"
143 };
144 File currentFile;
145
146 for (int i = 0; i < filenames.length; i++) {
147 currentFile = new File(filenames[i]);
148 assertEquals(expectedFileExt[i], IOUtils.getExtension(currentFile));
149 }
150
151 }
152
153 public void testGetLocalName() throws Exception {
154
155
156 }
157
158 public void testOpenCompressableInStream() throws Exception {
159
160
161 }
162
163 public void testOpenCompressableOutStream() throws Exception {
164
165
166 }
167
168 public void testOpenReader() throws Exception {
169
170
171 }
172
173 public void testOpenUnicodeReader() throws Exception {
174
175
176 }
177
178 public void testOpenUnicodeWriter() throws Exception {
179
180
181 }
182
183 public void testOpenWriter() throws Exception {
184
185
186 }
187
188 public void testReadToString() throws Exception {
189
190 final StringReader in = new StringReader(testString);
191 final String result = IOUtils.readToString(in);
192 in.close();
193 assertEquals(testString, result);
194
195 }
196
197 public void testReadToWriter() throws Exception {
198
199 final StringReader in = new StringReader(testString);
200 final Writer out = new StringWriter();
201 final int length = IOUtils.readToWriter(in, out);
202 assertEquals(testString, out.toString());
203 assertEquals(testString.length(), length);
204 in.close();
205 out.close();
206
207 }
208
209 public void testReadURIList() throws Exception {
210
211 final String uriListContents = "# urn:isbn:0-201-08372-8\r\n"
212 + "http://www.huh.org/books/foo.html#section2\n"
213 + "http://www.huh.org/books/foo.pdf\r\n"
214 + "ftp://ftp.foo.org/books/foo.txt\n"
215 + "#The URI list format is defined in\r\n"
216 + " # RFC 2483: \r"
217 + " http://www.rfc-editor.org/rfc/rfc2483.txt\n\r"
218 + " http://www.rfc-editor.org/ "
219 + "\r\n"
220 + "# It' stricter than this example but we should be \n"
221 + "\t## generous when reading.\r\n\r\n ";
222 final String[] expectedURIs = new String[] {
223 "http://www.huh.org/books/foo.html#section2",
224 "http://www.huh.org/books/foo.pdf",
225 "ftp://ftp.foo.org/books/foo.txt",
226 "http://www.rfc-editor.org/rfc/rfc2483.txt",
227 "http://www.rfc-editor.org/"
228 };
229
230 final String[] uris = IOUtils.readURIList(uriListContents);
231 assertEquals(uris.length, expectedURIs.length);
232 for (int i = 0; i < uris.length; i++) {
233 assertEquals(uris[i], expectedURIs[i]);
234 }
235
236 }
237
238 public void testSetGetDefaultDirectory() throws Exception {
239
240 java.io.File[] tests = {new java.io.File("."), null};
241
242 for (int i = 0; i < tests.length; i++) {
243 IOUtils.setDefaultDirectory(tests[i]);
244 assertEquals(tests[i], IOUtils.getDefaultDirectory());
245 }
246
247 }
248
249 public void testTryToClose() throws Exception {
250
251 Reader in = new StringReader(testString);
252 Writer out = new StringWriter();
253 InputStream inStream = new ByteArrayInputStream(new byte[1024]);
254 OutputStream outStream = new ByteArrayOutputStream(1024);
255
256
257 assertTrue(IOUtils.tryToClose(in));
258 assertTrue(IOUtils.tryToClose(out));
259 assertTrue(IOUtils.tryToClose(inStream));
260 assertTrue(IOUtils.tryToClose(outStream));
261
262
263 in = null;
264 out = null;
265 inStream = null;
266 outStream = null;
267
268 assertFalse(IOUtils.tryToClose(in));
269 assertFalse(IOUtils.tryToClose(out));
270 assertFalse(IOUtils.tryToClose(inStream));
271 assertFalse(IOUtils.tryToClose(outStream));
272
273 }
274
275 public void testWriteToWriter() throws Exception {
276
277
278 }
279
280
281
282 /***
283 * JUnitDoclet moves marker to this method, if there is not match
284 * for them in the regenerated code and if the marker is not empty.
285 * This way, no test gets lost when regenerating after renaming.
286 * Method testVault is supposed to be empty.
287 */
288 public void testVault() throws Exception {
289
290
291 }
292
293 public static void main(String[] args) {
294
295 junit.textui.TestRunner.run(IOUtilsTest.class);
296
297 }
298 }