use of ezvcard.util.Gobble in project ez-vcard by mangstadt.
the class JCardWriterTest method utf8.
@Test
public void utf8() throws Throwable {
VCard vcard = new VCard();
vcard.addNote("\u019dote");
File file = tempFolder.newFile();
JCardWriter writer = new JCardWriter(file);
writer.setAddProdId(false);
writer.write(vcard);
writer.close();
// @formatter:off
String expected = "[\"vcard\"," + "[" + "[\"version\",{},\"text\",\"4.0\"]," + "[\"note\",{},\"text\",\"\u019dote\"]" + "]" + "]";
// @formatter:on
String actual = new Gobble(file).asString("UTF-8");
assertEquals(expected, actual);
}
use of ezvcard.util.Gobble in project ez-vcard by mangstadt.
the class JCardWriterTest method assertExample.
public static void assertExample(String actual, String exampleFileName) throws IOException {
Filter filter = new Filter() {
public String filter(String json) {
// replace "date-and-or-time" data types with the data types ez-vcard uses
// ez-vcard avoids the use of "date-and-or-time"
json = json.replaceAll("\"bday\",\\{\\},\"date-and-or-time\"", "\"bday\",{},\"date\"");
json = json.replaceAll("\"anniversary\",\\{\\},\"date-and-or-time\"", "\"anniversary\",{},\"date-time\"");
return json;
}
};
String expected = new Gobble(JCardWriterTest.class.getResourceAsStream(exampleFileName)).asString();
expected = expected.replaceAll("\\s", "");
if (filter != null) {
expected = filter.filter(expected);
}
assertEquals(expected, actual);
}
use of ezvcard.util.Gobble in project ez-vcard by mangstadt.
the class VCardWriterTest method utf8.
@Test
public void utf8() throws Throwable {
VCard vcard = new VCard();
vcard.addNote("\u019dote");
File file = tempFolder.newFile();
// should be written as UTF-8
{
VCardWriter writer = new VCardWriter(file, false, VCardVersion.V4_0);
writer.setAddProdId(false);
writer.write(vcard);
writer.close();
// @formatter:off
String expected = "BEGIN:VCARD\r\n" + "VERSION:4.0\r\n" + "NOTE:\u019dote\r\n" + "END:VCARD\r\n";
// @formatter:on
String actual = new Gobble(file).asString("UTF-8");
assertEquals(expected, actual);
}
// should be written using default encoding
if (!Charset.defaultCharset().name().equalsIgnoreCase("UTF-8")) {
// don't test if the local machine's default encoding is UTF-8
VCardWriter writer = new VCardWriter(file, VCardVersion.V3_0);
writer.setAddProdId(false);
writer.write(vcard);
writer.close();
// @formatter:off
String expected = "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "NOTE:?ote\r\n" + "END:VCARD\r\n";
// @formatter:on
String actual = new Gobble(file).asString("UTF-8");
assertEquals(expected, actual);
}
}
use of ezvcard.util.Gobble in project ez-vcard by mangstadt.
the class XCardWriterTest method assertExample.
private void assertExample(VCard vcard, String exampleFileName) throws IOException, SAXException {
writer.write(vcard);
writer.close();
String expected = new Gobble(getClass().getResourceAsStream(exampleFileName)).asString();
String actual = sw.toString();
assertXMLEqual(expected, actual);
}
use of ezvcard.util.Gobble in project ez-vcard by mangstadt.
the class XCardWriterTest method write_utf8.
@Test
public void write_utf8() throws Exception {
File file = tempFolder.newFile();
XCardWriter writer = new XCardWriter(file);
writer.setAddProdId(false);
VCard vcard = new VCard();
vcard.addNote("\u019dote");
writer.write(vcard);
writer.close();
String xml = new Gobble(file).asString("UTF-8");
assertTrue(xml.matches("(?i)<\\?xml.*?encoding=\"utf-8\".*?\\?>.*"));
assertTrue(xml.matches(".*?<note><text>\u019dote</text></note>.*"));
}