1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.marshaller;
18
19 import static org.apache.juneau.TestUtils.*;
20
21 import java.io.*;
22 import java.util.*;
23
24 import org.apache.juneau.*;
25 import org.apache.juneau.collections.*;
26 import org.apache.juneau.parser.*;
27 import org.junit.jupiter.api.*;
28
29 class Csv_Test extends TestBase{
30
31 @Test void a01_to() throws Exception {
32 var in1 = "foo";
33 var in2 = new Object[]{JsonMap.of("a","foo","b","bar")};
34 var expected1 = "value\nfoo\n";
35 var expected2 = "a,b\nfoo,bar\n";
36
37 assertString(expected1, Csv.of(in1));
38 assertString(expected1, Csv.of(in1,stringWriter()));
39 assertString(expected2, Csv.of(in2));
40 assertString(expected2, Csv.of(in2,stringWriter()));
41 }
42
43 @Test void a02_from() {
44 var in1 = "'foo'";
45 var in2 = "{foo:'bar'}";
46
47 assertThrowsWithMessage(ParseException.class, "Not implemented.", ()->Csv.to(in1, String.class));
48 assertThrowsWithMessage(ParseException.class, "Not implemented.", ()->Csv.to(stringReader(in1), String.class));
49 assertThrowsWithMessage(ParseException.class, "Not implemented.", ()->Csv.to(in2, Map.class, String.class, String.class));
50 assertThrowsWithMessage(ParseException.class, "Not implemented.", ()->Csv.to(stringReader(in2), Map.class, String.class, String.class));
51 }
52
53
54
55
56 private Writer stringWriter() {
57 return new StringWriter();
58 }
59
60 private Reader stringReader(String s) {
61 return new StringReader(s);
62 }
63 }