use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.
the class JCardRawReaderTest method structured_value.
@Test
public void structured_value() throws Throwable {
// @formatter:off
String json = "[\"vcard\"," + "[" + "[\"prop\", {}, \"text\", [\"one\", [\"two\", \"three\"], \"four\"] ]," + "[\"prop\", {}, \"text\", [] ]" + "]" + "]";
// @formatter:on
JCardRawReader reader = createReader(json);
JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
reader.readNext(listener);
verify(listener).beginVCard();
verify(listener).readProperty(null, "prop", new VCardParameters(), VCardDataType.TEXT, JCardValue.structured("one", Arrays.asList("two", "three"), "four"));
verify(listener).readProperty(null, "prop", new VCardParameters(), VCardDataType.TEXT, JCardValue.structured());
verifyNoMoreInteractions(listener);
}
use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.
the class JCardRawReaderTest method read_multiple.
@Test
public void read_multiple() throws Throwable {
// @formatter:off
String json = "[" + "[\"vcard\"," + "[" + "[\"prop1\", {}, \"text\", \"one\"]," + "[\"prop2\", {}, \"integer\", 2]" + "]" + "]," + "[\"vcard\"," + "[" + "[\"prop1\", {}, \"text\", \"three\"]," + "[\"prop2\", {}, \"integer\", 4]" + "]" + "]" + "]";
// @formatter:on
JCardRawReader reader = createReader(json);
JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
reader.readNext(listener);
reader.readNext(listener);
verify(listener, times(2)).beginVCard();
verify(listener).readProperty(null, "prop1", new VCardParameters(), VCardDataType.TEXT, JCardValue.single("one"));
verify(listener).readProperty(null, "prop2", new VCardParameters(), VCardDataType.INTEGER, JCardValue.single(2L));
verify(listener).readProperty(null, "prop1", new VCardParameters(), VCardDataType.TEXT, JCardValue.single("three"));
verify(listener).readProperty(null, "prop2", new VCardParameters(), VCardDataType.INTEGER, JCardValue.single(4L));
verifyNoMoreInteractions(listener);
}
use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.
the class JCardRawReaderTest method data_type_unknown.
@Test
public void data_type_unknown() throws Throwable {
// @formatter:off
String json = "[\"vcard\"," + "[" + "[\"prop\", {}, \"unknown\", \"value\"]" + "]" + "]";
// @formatter:on
JCardRawReader reader = createReader(json);
JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
reader.readNext(listener);
verify(listener).beginVCard();
verify(listener).readProperty(null, "prop", new VCardParameters(), null, JCardValue.single("value"));
verifyNoMoreInteractions(listener);
}
use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.
the class JCardRawReaderTest method complex_value.
@Test
public void complex_value() throws Throwable {
// @formatter:off
String json = "[\"vcard\"," + "[" + "[\"prop\", {}, \"text\", {" + "\"a\":[\"one\",\"two\"]," + "\"b\":{" + "\"c\":[\"three\"]," + "\"d\":{}" + "}" + "}, \"four\" ]" + "]" + "]";
// @formatter:on
JCardRawReader reader = createReader(json);
JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
reader.readNext(listener);
List<JsonValue> expectedValues = new ArrayList<JsonValue>();
Map<String, JsonValue> m = new HashMap<String, JsonValue>();
{
// @formatter:off
m.put("a", new JsonValue(Arrays.asList(new JsonValue("one"), new JsonValue("two"))));
Map<String, JsonValue> m2 = new HashMap<String, JsonValue>();
{
m2.put("c", new JsonValue(Arrays.asList(new JsonValue("three"))));
m2.put("d", new JsonValue(new HashMap<String, JsonValue>()));
}
m.put("b", new JsonValue(m2));
// @formatter:on
}
expectedValues.add(new JsonValue(m));
expectedValues.add(new JsonValue("four"));
JCardValue expected = new JCardValue(expectedValues);
verify(listener).beginVCard();
verify(listener).readProperty(null, "prop", new VCardParameters(), VCardDataType.TEXT, expected);
verifyNoMoreInteractions(listener);
}
use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.
the class JCardRawWriterTest method parameters.
@Test
public void parameters() throws Throwable {
StringWriter sw = new StringWriter();
JCardRawWriter writer = new JCardRawWriter(sw, false);
writer.writeStartVCard();
VCardParameters parameters = new VCardParameters();
parameters.put("a", "value1");
parameters.put("b", "value2");
parameters.put("b", "value3");
writer.writeProperty(null, "prop", parameters, VCardDataType.TEXT, JCardValue.single("value"));
writer.close();
String actual = sw.toString();
// @formatter:off
String expected = "[\"vcard\"," + "[" + "[\"prop\",{\"a\":\"value1\",\"b\":[\"value2\",\"value3\"]},\"text\",\"value\"]" + "]" + "]";
// @formatter:on
assertEquals(expected, actual);
}
Aggregations