1   package de.fu_berlin.ties.io;
2   
3   import junit.framework.TestCase;
4   // JUnitDoclet begin import
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  // JUnitDoclet end import
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  // JUnitDoclet begin extends_implements
28  extends TestCase
29  // JUnitDoclet end extends_implements
30  {
31    // JUnitDoclet begin class
32    private static final String testString =
33      "This is just a simple test string without any real value";
34    // JUnitDoclet end class
35    
36    public IOUtilsTest(String name) {
37      // JUnitDoclet begin method IOUtilsTest
38      super(name);
39      // JUnitDoclet end method IOUtilsTest
40    }
41    
42    public de.fu_berlin.ties.io.IOUtils createInstance() throws Exception {
43      // JUnitDoclet begin method testcase.createInstance
44      return null; // singleton
45      // JUnitDoclet end method testcase.createInstance
46    }
47    
48    protected void setUp() throws Exception {
49      // JUnitDoclet begin method testcase.setUp
50      super.setUp();
51      // JUnitDoclet end method testcase.setUp
52    }
53    
54    protected void tearDown() throws Exception {
55      // JUnitDoclet begin method testcase.tearDown
56      super.tearDown();
57      // JUnitDoclet end method testcase.tearDown
58    }
59    
60    public void testCreateOutFile() throws Exception {
61      // JUnitDoclet begin method createOutFile
62      // JUnitDoclet end method createOutFile
63    }
64    
65    public void testDetermineCharset() throws Exception {
66      // JUnitDoclet begin method determineCharset
67      // JUnitDoclet end method determineCharset
68    }
69    
70    public void testDetermineCharsetName() throws Exception {
71      // JUnitDoclet begin method determineCharsetName
72      // JUnitDoclet end method determineCharsetName
73    }
74    
75    public void testDetermineOutputDirectory() throws Exception {
76      // JUnitDoclet begin method determineOutputDirectory
77      // JUnitDoclet end method determineOutputDirectory
78    }
79    
80    public void testGetBaseName() throws Exception {
81      // JUnitDoclet begin method getBaseName
82      // JUnitDoclet end method getBaseName
83    }
84    
85    public void testGetExtension() throws Exception {
86      // JUnitDoclet begin method getExtension
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&param2=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     // JUnitDoclet end method getExtension
151   }
152   
153   public void testGetLocalName() throws Exception {
154     // JUnitDoclet begin method getLocalName
155     // JUnitDoclet end method getLocalName
156   }
157   
158   public void testOpenCompressableInStream() throws Exception {
159     // JUnitDoclet begin method openCompressableInStream
160     // JUnitDoclet end method openCompressableInStream
161   }
162   
163   public void testOpenCompressableOutStream() throws Exception {
164     // JUnitDoclet begin method openCompressableOutStream
165     // JUnitDoclet end method openCompressableOutStream
166   }
167   
168   public void testOpenReader() throws Exception {
169     // JUnitDoclet begin method openReader
170     // JUnitDoclet end method openReader
171   }
172   
173   public void testOpenUnicodeReader() throws Exception {
174     // JUnitDoclet begin method openUnicodeReader
175     // JUnitDoclet end method openUnicodeReader
176   }
177   
178   public void testOpenUnicodeWriter() throws Exception {
179     // JUnitDoclet begin method openUnicodeWriter
180     // JUnitDoclet end method openUnicodeWriter
181   }
182   
183   public void testOpenWriter() throws Exception {
184     // JUnitDoclet begin method openWriter
185     // JUnitDoclet end method openWriter
186   }
187   
188   public void testReadToString() throws Exception {
189     // JUnitDoclet begin method readToString
190     final StringReader in = new StringReader(testString);
191     final String result = IOUtils.readToString(in);
192     in.close();
193     assertEquals(testString, result);
194     // JUnitDoclet end method readToString
195   }
196   
197   public void testReadToWriter() throws Exception {
198     // JUnitDoclet begin method readToWriter
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     // JUnitDoclet end method readToWriter
207   }
208   
209   public void testReadUntilLineEnd() throws Exception {
210     // JUnitDoclet begin method readUntilLineEnd
211     // JUnitDoclet end method readUntilLineEnd
212   }
213   
214   public void testReadURIList() throws Exception {
215     // JUnitDoclet begin method readURIList
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     // JUnitDoclet end method readURIList
241   }
242   
243   public void testResolveFilename() throws Exception {
244     // JUnitDoclet begin method resolveFilename
245     // JUnitDoclet end method resolveFilename
246   }
247   
248   public void testSetGetDefaultDirectory() throws Exception {
249     // JUnitDoclet begin method setDefaultDirectory getDefaultDirectory
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     // JUnitDoclet end method setDefaultDirectory getDefaultDirectory
257   }
258   
259   public void testTryToClose() throws Exception {
260     // JUnitDoclet begin method tryToClose
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     // should be closeable
267     assertTrue(IOUtils.tryToClose(in));
268     assertTrue(IOUtils.tryToClose(out));
269     assertTrue(IOUtils.tryToClose(inStream));
270     assertTrue(IOUtils.tryToClose(outStream));
271     
272     // should return false for null objects
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     // JUnitDoclet end method tryToClose
283   }
284   
285   public void testUserDir() throws Exception {
286     // JUnitDoclet begin method userDir
287     // JUnitDoclet end method userDir
288   }
289   
290   public void testUserHome() throws Exception {
291     // JUnitDoclet begin method userHome
292     // JUnitDoclet end method userHome
293   }
294   
295   public void testWriteLine() throws Exception {
296     // JUnitDoclet begin method writeLine
297     // JUnitDoclet end method writeLine
298   }
299   
300   public void testWriteToWriter() throws Exception {
301     // JUnitDoclet begin method writeToWriter
302     // JUnitDoclet end method writeToWriter
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     // JUnitDoclet begin method testcase.testVault
315     // JUnitDoclet end method testcase.testVault
316   }
317   
318   public static void main(String[] args) {
319     // JUnitDoclet begin method testcase.main
320     junit.textui.TestRunner.run(IOUtilsTest.class);
321     // JUnitDoclet end method testcase.main
322   }
323 }