Search in sources :

Example 1 with ParseWarning

use of ezvcard.io.ParseWarning in project ez-vcard by mangstadt.

the class EzvcardTest method parseXml_all.

@Test
public void parseXml_all() throws Exception {
    XCardBuilder xb = new XCardBuilder();
    xb.prop("fn", "<text>John Doe</text>");
    xb.begin();
    xb.prop("fn", "<text>Jane Doe</text>");
    List<List<ParseWarning>> warnings = new ArrayList<List<ParseWarning>>();
    List<VCard> vcards = Ezvcard.parseXml(xb.toString()).warnings(warnings).all();
    Iterator<VCard> it = vcards.iterator();
    VCard vcard = it.next();
    assertVersion(VCardVersion.V4_0, vcard);
    assertEquals("John Doe", vcard.getFormattedName().getValue());
    vcard = it.next();
    assertVersion(VCardVersion.V4_0, vcard);
    assertEquals("Jane Doe", vcard.getFormattedName().getValue());
    assertEquals(2, warnings.size());
    assertParseWarnings(warnings.get(0));
    assertParseWarnings(warnings.get(1));
    assertFalse(it.hasNext());
}
Also used : ArrayList(java.util.ArrayList) XCardBuilder(ezvcard.util.XCardBuilder) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) ParseWarning(ezvcard.io.ParseWarning) Test(org.junit.Test)

Example 2 with ParseWarning

use of ezvcard.io.ParseWarning in project ez-vcard by mangstadt.

the class TestUtils method assertParseWarnings.

/**
 * Asserts a list of parse warnings.
 * @param warnings the parse warnings
 * @param expectedCodes the expected warning codes (order does not matter,
 * use "null" for warnings that do not have a code)
 */
public static void assertParseWarnings(List<ParseWarning> warnings, Integer... expectedCodes) {
    List<Integer> expectedWarnings = new ArrayList<Integer>(Arrays.asList(expectedCodes));
    List<Integer> actualWarnings = new ArrayList<Integer>(warnings.size());
    for (ParseWarning warning : warnings) {
        actualWarnings.add(warning.getCode());
    }
    for (Integer actualWarning : actualWarnings) {
        if (!expectedWarnings.remove(actualWarning)) {
            fail("Expected these warnings " + expectedWarnings + ", but was this: " + actualWarnings + ".  Actual warnings: " + warnings);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ParseWarning(ezvcard.io.ParseWarning)

Example 3 with ParseWarning

use of ezvcard.io.ParseWarning in project ez-vcard by mangstadt.

the class EzvcardTest method parseXml_first.

@Test
public void parseXml_first() throws Exception {
    XCardBuilder xb = new XCardBuilder();
    xb.prop("fn", "<text>John Doe</text>");
    List<List<ParseWarning>> warnings = new ArrayList<List<ParseWarning>>();
    VCard vcard = Ezvcard.parseXml(xb.toString()).warnings(warnings).first();
    assertVersion(VCardVersion.V4_0, vcard);
    assertEquals("John Doe", vcard.getFormattedName().getValue());
    assertEquals(1, warnings.size());
    assertParseWarnings(warnings.get(0));
}
Also used : ArrayList(java.util.ArrayList) XCardBuilder(ezvcard.util.XCardBuilder) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) ParseWarning(ezvcard.io.ParseWarning) Test(org.junit.Test)

Aggregations

ParseWarning (ezvcard.io.ParseWarning)3 ArrayList (java.util.ArrayList)3 XCardBuilder (ezvcard.util.XCardBuilder)2 List (java.util.List)2 Test (org.junit.Test)2 NodeList (org.w3c.dom.NodeList)2