Hi, I'm not a commiter, but if I may share may point of view, I also prefer working with files when they are of certain size. It's easier to edit it with you IDE :) Instead of placing the file somewhere in the path, I place it within the package path. It can be fetched as a resource from the class. A bonus is that the location if the file does not matter, as long as the classpath is correct. Example (not tested, view it as pseudo code:) ) public byte[] readResourceExample() throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); InputStream in = null; try { // (option 1) in = getClass().getResourceAsStream( "/rootPackage/myfile.html" ); // (option 2) in = getClass().getResourceAsStream( "childPackageOfCurrentClassPackage/myfile.html" ); BufferedInputStream bin = new BufferedInputStream( in ); int read; byte[] buffer = new byte[1024]; while ( (read = bin.read( buffer )) >= 0 ) { bout.write( buffer, 0, read ); } } finally { if ( in != null ) { try { in.close(); } catch ( IOException e ) { // ignore } } } return bout.toByteArray(); } Regards, Melv On 3/29/07, Christian Gmeiner <[email protected]> wrote:
Hi,
Why do you have to work with files? If I were you I'd work with content in memory, not files. That's much better because:
I load the files into memory :)
1/ The test and the input data are in the same location making it easier to understand and maintain the test
Adding about 150 lines (html and xwiki) makes the test file very very big. I have here laying much bigger html files (400 lines because of the <style> stuff) and I dont want to add them.
2/ No IO thus less complex (your post proves it)
But is very hard to add 150 lines of a String to the source. Have a look at:
html = "<table border=1 cellspacing=0 cellpadding=0 style='border-collapse:collapse;" + "border:none;mso-border-alt:solid windowtext .5pt;mso-padding-alt:0cm 3.5pt 0cm 3.5pt'>" + " <tr>" + " <td width=179 valign=top style='width:107.15pt;border:solid windowtext .5pt;" + " padding:0cm 3.5pt 0cm 3.5pt'>"
+ " <p class=MsoNormal style='margin-top:3.0pt;margin-right:0cm;margin-bottom:" + " 3.0pt;margin-left:0cm;line-height:150%'><span lang=DE style='color:black;" + " layout-grid-mode:line'>Date <o:p></o:p></span></p>" + " </td>" + " <td width=179 valign=top style='width:107.2pt;border:solid windowtext .5pt;" + " border-left:none;mso-border-left-alt:solid windowtext .5pt;padding:0cm 3.5pt 0cm 3.5pt'>" + " <p class=MsoNormal style='margin-top:3.0pt;margin-right:0cm;margin-bottom:" + " 3.0pt;margin-left:0cm;line-height:150%'><span lang=DE style='color:black;" + " layout-grid-mode:line'>Version<o:p></o:p></span></p>" + " </td>" + " <td width=179 valign=top style='width:107.2pt;border:solid windowtext .5pt;" + " border-left:none;mso-border-left-alt:solid windowtext .5pt;padding:0cm 3.5pt 0cm 3.5pt'>" + " <p class=MsoNormal style='margin-top:3.0pt;margin-right:0cm;margin-bottom:" + " 3.0pt;margin-left:0cm;line-height:150%'><span lang=DE style='color:black;" + " layout-grid-mode:line'>Description<o:p></o:p></span></p>"
+ " </td>" + " <td width=179 valign=top style='width:107.2pt;border:solid windowtext .5pt;" + " border-left:none;mso-border-left-alt:solid windowtext .5pt;padding:0cm 3.5pt 0cm 3.5pt'>" + " <p class=MsoNormal style='margin-top:3.0pt;margin-right:0cm;margin-bottom:" + " 3.0pt;margin-left:0cm;line-height:150%'><span lang=DE style='color:black;" + " layout-grid-mode:line'>Author<o:p></o:p></span></p>" + " </td>" + " </tr>" + "<tr>" + " <td width=179 valign=top style='width:107.15pt;border:solid windowtext .5pt;" + " border-top:none;mso-border-top-alt:solid windowtext .5pt;padding:0cm 3.5pt 0cm 3.5pt'>" + " <p class=ProjektStandard style='margin-top:3.0pt;margin-right:0cm;margin-bottom:" + " 3.0pt;margin-left:0cm;line-height:150%'><span lang=DE>09.04.2006</span></p>"
+ " </td>" + " <td width=179 valign=top style='width:107.2pt;border-top:none;border-left:" + " none;border-bottom:solid windowtext .5pt;border-right:solid windowtext .5pt;" + " mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;" + " padding:0cm 3.5pt 0cm 3.5pt'>" + " <p class=ProjektStandard style='margin-top:3.0pt;margin-right:0cm;margin-bottom:" + " 3.0pt;margin-left:0cm;line-height:150%'><span lang=DE>1.0</span></p>" + " </td>" + " <td width=179 valign=top style='width:107.2pt;border-top:none;border-left:v" + " none;border-bottom:solid windowtext .5pt;border-right:solid windowtext .5pt;" + " mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;" + " padding:0cm 3.5pt 0cm 3.5pt'>" + " <p class=ProjektStandard style='margin-top:3.0pt;margin-right:0cm;margin-bottom:" + " 3.0pt;margin-left:0cm;line-height:150%'><span lang=DE>Bla</span></p>"
+ " </td>" + " <td width=179 valign=top style='width:107.2pt;border-top:none;border-left:" + " none;border-bottom:solid windowtext .5pt;border-right:solid windowtext .5pt;" + " mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;" + " padding:0cm 3.5pt 0cm 3.5pt'>" + " <p class=MsoNormal style='margin-top:3.0pt;margin-right:0cm;margin-bottom:" + " 3.0pt;margin-left:0cm;line-height:150%'><span lang=DE style='color:black;" + " layout-grid-mode:line'>Christian<o:p></o:p></span></p>" + " </td>" + " </tr>" + "</table>";
Doing copy and paste in a file is much easier to handle...
3/ Much faster
For me its no problem if the test is a little bit slower... the quality of tests are much important.
Greets, Christian
-- You receive this message as a subscriber of the [email protected] mailing list. To unsubscribe: mailto:[email protected] For general help: mailto:[email protected]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws