Search in sources :

Example 31 with VCard

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);
}
Also used : ArrayList(java.util.ArrayList) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 32 with VCard

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);
}
Also used : StringWriter(java.io.StringWriter) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 33 with VCard

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);
}
Also used : VCard(ezvcard.VCard) Test(org.junit.Test)

Example 34 with VCard

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);
}
Also used : Gobble(ezvcard.util.Gobble) VCard(ezvcard.VCard) File(java.io.File) Test(org.junit.Test)

Example 35 with VCard

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");
}
Also used : StringWriter(java.io.StringWriter) VCard(ezvcard.VCard) Test(org.junit.Test)

Aggregations

VCard (ezvcard.VCard)189 Test (org.junit.Test)134 StringWriter (java.io.StringWriter)29 StructuredName (ezvcard.property.StructuredName)23 Person (com.google.api.services.people.v1.model.Person)22 Telephone (ezvcard.property.Telephone)21 Photo (ezvcard.property.Photo)17 Email (ezvcard.property.Email)16 List (java.util.List)16 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)15 Document (org.w3c.dom.Document)15 VCardVersion (ezvcard.VCardVersion)14 XCardDocumentStreamWriter (ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter)14 Address (ezvcard.property.Address)14 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)13 Collectors (java.util.stream.Collectors)12 Name (com.google.api.services.people.v1.model.Name)11 File (java.io.File)11 Truth.assertThat (com.google.common.truth.Truth.assertThat)10 Pair (com.google.gdata.util.common.base.Pair)10