Ejemplo n.º 1
0
 @Test
 public void writeRow() throws IOException {
   StringWriter writer = new StringWriter();
   RowInstructions instructions = new RowInstructionsImpl().setUseHeader(false);
   RowWriter rowWriter = new RowWriterImpl(writer, instructions);
   rowWriter.writeRow(new String[] {"alpha", "beta", "gamma"});
   writer.close();
   assertEquals("\"alpha\";\"beta\";\"gamma\"\r", writer.getBuffer().toString());
 }
Ejemplo n.º 2
0
 @Test
 public void writeRowWithEscapeCharacters() throws IOException {
   StringWriter writer = new StringWriter();
   RowInstructions instructions = new RowInstructionsImpl().setUseHeader(false).setEscape('\\');
   RowWriter rowWriter = new RowWriterImpl(writer, instructions);
   rowWriter.writeRow(new String[] {"\"tekst met \"quotes\"\""});
   writer.close();
   assertEquals("\"\\\"tekst met \\\"quotes\\\"\\\"\"\r", writer.getBuffer().toString());
 }
Ejemplo n.º 3
0
 @Test
 public void writeRowAndHeader() throws IOException {
   StringWriter writer = new StringWriter();
   RowWriter rowWriter = new RowWriterImpl(writer);
   rowWriter.writeHeader(new String[] {"desc1", "desc2", "desc3"});
   rowWriter.writeRow(new String[] {"alpha", "beta", "gamma"});
   writer.close();
   assertEquals(
       "\"desc1\";\"desc2\";\"desc3\"\r" + "\"alpha\";\"beta\";\"gamma\"\r",
       writer.getBuffer().toString());
 }
Ejemplo n.º 4
0
 @Test(expected = CsvException.class)
 public void noHeaderWritten() {
   RowWriter rowWriter = new RowWriterImpl(new StringWriter());
   rowWriter.writeRow(new String[] {"alpha", "beta", "gamma"});
 }