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 testReadUntilLineEnd() throws Exception {
210
211
212 }
213
214 public void testReadURIList() throws Exception {
215
216 final String uriListContents = "# urn:isbn:0-201-08372-8\r\n"
217 + "http://www.huh.org/books/foo.html#section2\n"
218 + "http://www.huh.org/books/foo.pdf\r\n"
219 + "ftp://ftp.foo.org/books/foo.txt\n"
220 + "#The URI list format is defined in\r\n"
221 + " # RFC 2483: \r"
222 + " http://www.rfc-editor.org/rfc/rfc2483.txt\n\r"
223 + " http://www.rfc-editor.org/ "
224 + "\r\n"
225 + "# It' stricter than this example but we should be \n"
226 + "\t## generous when reading.\r\n\r\n ";
227 final String[] expectedURIs = new String[] {
228 "http://www.huh.org/books/foo.html#section2",
229 "http://www.huh.org/books/foo.pdf",
230 "ftp://ftp.foo.org/books/foo.txt",
231 "http://www.rfc-editor.org/rfc/rfc2483.txt",
232 "http://www.rfc-editor.org/"
233 };
234
235 final String[] uris = IOUtils.readURIList(uriListContents);
236 assertEquals(uris.length, expectedURIs.length);
237 for (int i = 0; i < uris.length; i++) {
238 assertEquals(uris[i], expectedURIs[i]);
239 }
240
241 }
242
243 public void testResolveFilename() throws Exception {
244
245
246 }
247
248 public void testSetGetDefaultDirectory() throws Exception {
249
250 java.io.File[] tests = {new java.io.File("."), null};
251
252 for (int i = 0; i < tests.length; i++) {
253 IOUtils.setDefaultDirectory(tests[i]);
254 assertEquals(tests[i], IOUtils.getDefaultDirectory());
255 }
256
257 }
258
259 public void testTryToClose() throws Exception {
260
261 Reader in = new StringReader(testString);
262 Writer out = new StringWriter();
263 InputStream inStream = new ByteArrayInputStream(new byte[1024]);
264 OutputStream outStream = new ByteArrayOutputStream(1024);
265
266
267 assertTrue(IOUtils.tryToClose(in));
268 assertTrue(IOUtils.tryToClose(out));
269 assertTrue(IOUtils.tryToClose(inStream));
270 assertTrue(IOUtils.tryToClose(outStream));
271
272
273 in = null;
274 out = null;
275 inStream = null;
276 outStream = null;
277
278 assertFalse(IOUtils.tryToClose(in));
279 assertFalse(IOUtils.tryToClose(out));
280 assertFalse(IOUtils.tryToClose(inStream));
281 assertFalse(IOUtils.tryToClose(outStream));
282
283 }
284
285 public void testUserDir() throws Exception {
286
287
288 }
289
290 public void testUserHome() throws Exception {
291
292
293 }
294
295 public void testWriteLine() throws Exception {
296
297
298 }
299
300 public void testWriteToWriter() throws Exception {
301
302
303 }
304
305
306
307 /***
308 * JUnitDoclet moves marker to this method, if there is not match
309 * for them in the regenerated code and if the marker is not empty.
310 * This way, no test gets lost when regenerating after renaming.
311 * Method testVault is supposed to be empty.
312 */
313 public void testVault() throws Exception {
314
315
316 }
317
318 public static void main(String[] args) {
319
320 junit.textui.TestRunner.run(IOUtilsTest.class);
321
322 }
323 }