use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.
the class VCardPropertyScribeTest method parseXml.
@Test
public void parseXml() {
final VCardParameters params = new VCardParameters();
// @formatter:off
sensei.assertParseXml("<ignore xmlns=\"http://example.com\">ignore-me</ignore>" + "<integer>value</integer>" + "<text>ignore-me</text>").params(params).warnings((Integer) null).run(new Check<TestProperty>() {
public void check(TestProperty property) {
assertEquals("value", property.value);
assertEquals(VCardDataType.INTEGER, property.parsedDataType);
assertSame(params, property.getParameters());
}
});
// @formatter:on
}
use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.
the class VCardPropertyScribeTest method handlePrefParam_from_4.
@Test
public void handlePrefParam_from_4() {
VCard vcard = new VCard();
TestProperty two = new TestProperty("");
two.getParameters().setPref(2);
vcard.addProperty(two);
TestProperty nullPref = new TestProperty("");
vcard.addProperty(nullPref);
TestProperty invalidPref = new TestProperty("");
invalidPref.getParameters().replace("PREF", "invalid");
vcard.addProperty(invalidPref);
TestProperty one = new TestProperty("");
one.getParameters().setPref(1);
vcard.addProperty(one);
TestProperty three = new TestProperty("");
three.getParameters().setPref(3);
vcard.addProperty(three);
// no change
{
VCardVersion version = V4_0;
for (TestProperty p : vcard.getProperties(TestProperty.class)) {
VCardParameters copy = new VCardParameters(p.getParameters());
VCardPropertyScribe.handlePrefParam(p, copy, version, vcard);
assertEquals(p.getParameters(), copy);
}
}
for (VCardVersion version : each(V2_1, V3_0)) {
VCardParameters copy = new VCardParameters(one.getParameters());
VCardPropertyScribe.handlePrefParam(one, copy, version, vcard);
assertEquals("pref", copy.getType());
assertNull(copy.getPref());
for (TestProperty p : each(nullPref, invalidPref, two, three)) {
copy = new VCardParameters(p.getParameters());
VCardPropertyScribe.handlePrefParam(p, copy, version, vcard);
assertNull(copy.getType());
assertNull(copy.getPref());
}
}
}
use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.
the class VCardPropertyScribeTest method handlePrefParam_to_4.
@Test
public void handlePrefParam_to_4() {
VCard vcard = new VCard();
TestProperty two = new TestProperty("");
two.getParameters().setType("HOME");
vcard.addProperty(two);
TestProperty one = new TestProperty("");
one.getParameters().setType("PREF");
vcard.addProperty(one);
TestProperty three = new TestProperty("");
vcard.addProperty(three);
// no change
for (VCardVersion version : each(V2_1, V3_0)) {
for (TestProperty p : vcard.getProperties(TestProperty.class)) {
VCardParameters copy = new VCardParameters(p.getParameters());
VCardPropertyScribe.handlePrefParam(p, copy, version, vcard);
assertEquals(p.getParameters(), copy);
}
}
{
VCardVersion version = V4_0;
VCardParameters copy = new VCardParameters(one.getParameters());
VCardPropertyScribe.handlePrefParam(one, copy, version, vcard);
assertIntEquals(1, copy.getPref());
assertNull(copy.getType());
for (TestProperty p : each(two, three)) {
copy = new VCardParameters(p.getParameters());
VCardPropertyScribe.handlePrefParam(p, copy, version, vcard);
assertEquals(p.getParameters(), copy);
}
}
}
use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.
the class VCardPropertyTest method parameters.
@Test
public void parameters() {
VCardPropertyImpl property = new VCardPropertyImpl();
assertEquals(new VCardParameters(), property.getParameters());
try {
property.setParameters(null);
fail("NPE expected.");
} catch (NullPointerException e) {
// expected
}
VCardParameters parameters = new VCardParameters();
property.setParameters(parameters);
assertSame(parameters, property.getParameters());
property.addParameter("PARAM", "value");
property.addParameter("PARAM", "value2");
assertEquals("value", property.getParameter("PARAM"));
assertEquals(Arrays.asList("value", "value2"), property.getParameters("PARAM"));
VCardParameters expected = new VCardParameters();
expected.put("PARAM", "value");
expected.put("PARAM", "value2");
assertEquals(expected, property.getParameters());
property.setParameter("PARAM", "one");
assertEquals("one", property.getParameter("PARAM"));
assertEquals(Arrays.asList("one"), property.getParameters("PARAM"));
expected = new VCardParameters();
expected.put("PARAM", "one");
assertEquals(expected, property.getParameters());
property.removeParameter("PARAM");
assertNull(property.getParameter("PARAM"));
assertEquals(Arrays.asList(), property.getParameters("PARAM"));
expected = new VCardParameters();
assertEquals(expected, property.getParameters());
}
use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.
the class PidParameterListTest method get_set.
@Test
public void get_set() {
PidParameterListProperty property = new PidParameterListProperty();
VCardParameters parameters = property.getParameters();
List<Pid> pids = property.getPids();
pids.add(new Pid(1, 1));
parameters.put(VCardParameters.PID, "2");
assertEquals(Arrays.asList("1.1", "2"), parameters.get(VCardParameters.PID));
assertEquals(Arrays.asList(new Pid(1, 1), new Pid(2)), pids);
}
Aggregations