Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: junit/framework/ZStringArrayStreamWriter.java


1   package junit.framework;
2   
3   import java.io.IOException;
4   import java.io.StringWriter;
5   
6   import junit.framework.TestCase;
7   
8   import net.sourceforge.jbird.io.StringArrayStreamWriter;
9   
10  /**
11    * A junit test class for net.sourceforge.jbird.io.StringArrayStreamWriter.
12    * @author Dick Repasky
13    * @since J-Bird 0.1.2
14    * @see net.sourceforge.jbird.TestJB
15    * @see net.sourceforge.jbird.io.StringArrayStreamWriter
16  */
17  
18  public class ZStringArrayStreamWriter extends TestCase {
19  
20    public ZStringArrayStreamWriter (String name) {
21      super(name);
22    }
23  
24    protected void setUp() {
25    }
26  
27    protected void tearDown() {
28    }
29  
30  
31    public void testNoQuotes() throws IOException {
32      String[] testdata = { "no", "quoted", "text" };
33      String correct = "no,quoted,text\n";
34      StringWriter sw = new StringWriter();
35      StringArrayStreamWriter sasw = new StringArrayStreamWriter(
36          sw, ",");
37      sasw.setDelimiterQuote('"');
38      sasw.write(testdata);
39      sasw.close();
40      String answer = sw.toString();
41      assertEquals ("testNoQuotes", correct, answer);
42     }
43  
44    public void testQuotes() throws IOException {
45      String[] testdata = { "a , first", "no second", "a , third" };
46      String correct = "\"a , first\",no second,\"a , third\"\n";
47      StringWriter sw = new StringWriter();
48      StringArrayStreamWriter sasw = new StringArrayStreamWriter(
49          sw, ",");
50      sasw.setDelimiterQuote('"');
51      sasw.write(testdata);
52      sasw.close();
53      String answer = sw.toString();
54      assertEquals ("testQuotes", correct, answer);
55     }
56  
57    public void testInteriorQuotes() throws IOException {
58      String[] testdata = { "hey \"dude\"", "\"MONDO\"", "ana\"\"conda" };
59      String correct = "\"hey \"\"dude\"\"\",\"\"\"MONDO\"\"\",\"ana\"\"\"\"conda\"\n";
60      StringWriter sw = new StringWriter();
61      StringArrayStreamWriter sasw = new StringArrayStreamWriter(
62          sw, ",");
63      sasw.setDelimiterQuote('"');
64      sasw.write(testdata);
65      sasw.close();
66      String answer = sw.toString();
67      //System.out.println(correct);
68      //System.out.println(answer);
69      assertEquals ("testInteriorQuotes", correct, answer);
70     }
71  
72  }