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());
}
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);
}
}
}
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));
}
Aggregations