use of ezvcard.io.json.JCardRawReader.JCardDataStreamListener 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.io.json.JCardRawReader.JCardDataStreamListener 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.io.json.JCardRawReader.JCardDataStreamListener in project ez-vcard by mangstadt.
the class JCardRawReaderTest method empty_properties_array.
@Test
public void empty_properties_array() throws Throwable {
// @formatter:off
String json = "[\"vcard\"," + "[" + "]" + "]";
// @formatter:on
JCardRawReader reader = createReader(json);
JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
reader.readNext(listener);
verify(listener).beginVCard();
verifyNoMoreInteractions(listener);
}
use of ezvcard.io.json.JCardRawReader.JCardDataStreamListener 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.io.json.JCardRawReader.JCardDataStreamListener 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);
}
Aggregations