use of ezvcard.VCard in project ez-vcard by mangstadt.
the class JCardSerializerTest method serialize_multiple.
@Test
public void serialize_multiple() throws Exception {
List<VCard> vcards = new ArrayList<VCard>();
VCard vcard = new VCard();
vcard.setFormattedName("John Doe");
vcards.add(vcard);
vcard = new VCard();
vcard.setFormattedName("Jane Doe");
vcards.add(vcard);
JCardModule module = new JCardModule();
module.setAddProdId(false);
mapper.registerModule(module);
String actual = mapper.writeValueAsString(vcards);
// @formatter:off
String expected = "[" + "[\"vcard\"," + "[" + "[\"version\",{},\"text\",\"4.0\"]," + "[\"fn\",{},\"text\",\"John Doe\"]" + "]" + "]," + "[\"vcard\"," + "[" + "[\"version\",{},\"text\",\"4.0\"]," + "[\"fn\",{},\"text\",\"Jane Doe\"]" + "]" + "]" + "]";
// @formatter:on
assertEquals(expected, actual);
}
use of ezvcard.VCard in project ez-vcard by mangstadt.
the class JCardSerializerTest method container_annotation.
@Test
public void container_annotation() throws Exception {
VCard vcard = new VCard();
vcard.setFormattedName("John Doe");
vcard.setMailer("mailer");
ContainerAnnotation container = new ContainerAnnotation(vcard);
StringWriter result = new StringWriter();
mapper.writeValue(result, container);
String actual = result.toString();
// @formatter:off
String expected = "{" + "\"contact\":[\"vcard\"," + "[" + "[\"version\",{},\"text\",\"4.0\"]," + "[\"fn\",{},\"text\",\"John Doe\"]," + "[\"mailer\",{},\"text\",\"mailer\"]" + "]" + "]" + "}";
// @formatter:on
assertEquals(expected, actual);
}
use of ezvcard.VCard in project ez-vcard by mangstadt.
the class JCardSerializerTest method serialize_single_prettyPrint.
@Test
public void serialize_single_prettyPrint() throws Exception {
VCard vcard = new VCard();
vcard.setFormattedName("John Doe");
JCardModule module = new JCardModule();
module.setAddProdId(false);
mapper.registerModule(module);
mapper.setDefaultPrettyPrinter(new JCardPrettyPrinter());
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
String actual = mapper.writeValueAsString(vcard);
// @formatter:off
String expected = "[" + NEWLINE + " \"vcard\"," + NEWLINE + " [" + NEWLINE + " [ \"version\", { }, \"text\", \"4.0\" ]," + NEWLINE + " [ \"fn\", { }, \"text\", \"John Doe\" ]" + NEWLINE + " ]" + NEWLINE + "]";
// @formatter:on
assertEquals(expected, actual);
}
use of ezvcard.VCard 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.VCard in project ez-vcard by mangstadt.
the class JCardWriterTest method jcard_example.
@Test
public void jcard_example() throws Throwable {
VCard vcard = createExample();
assertValidate(vcard).versions(VCardVersion.V4_0).run();
StringWriter sw = new StringWriter();
JCardWriter writer = new JCardWriter(sw);
writer.setAddProdId(false);
writer.write(vcard);
writer.close();
String actual = sw.toString();
assertExample(actual, "jcard-example.json");
}
Aggregations