use of ezvcard.io.json.JCardRawReader.JCardDataStreamListener in project ez-vcard by mangstadt.
the class JCardRawReaderTest method basic.
@Test
public void basic() throws Throwable {
// @formatter:off
String json = "[\"vcard\"," + "[" + "[\"prop1\", {}, \"text\", \"one\"]," + "[\"prop2\", {}, \"integer\", 2]" + "]" + "]";
// @formatter:on
JCardRawReader reader = createReader(json);
JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
reader.readNext(listener);
verify(listener).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));
verifyNoMoreInteractions(listener);
}
use of ezvcard.io.json.JCardRawReader.JCardDataStreamListener in project ez-vcard by mangstadt.
the class JCardRawReaderTest method multi_value.
@Test
public void multi_value() throws Throwable {
// @formatter:off
String json = "[\"vcard\"," + "[" + "[\"prop\", {}, \"text\", \"one\", \"two\", \"three\" ]," + "[\"prop\", {}, \"text\", \"one\" ]" + "]" + "]";
// @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.multi("one", "two", "three"));
verify(listener).readProperty(null, "prop", new VCardParameters(), VCardDataType.TEXT, JCardValue.multi("one"));
verifyNoMoreInteractions(listener);
}
use of ezvcard.io.json.JCardRawReader.JCardDataStreamListener in project ez-vcard by mangstadt.
the class JCardRawReaderTest method parameters.
@Test
public void parameters() throws Throwable {
// @formatter:off
String json = "[\"vcard\"," + "[" + "[\"prop\", { \"a\": \"one\", \"b\": [\"two\"], \"c\": [\"three\", \"four\"] }, \"text\", \"value\"]" + "]" + "]";
// @formatter:on
JCardRawReader reader = createReader(json);
JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
reader.readNext(listener);
VCardParameters expected = new VCardParameters();
expected.put("a", "one");
expected.put("b", "two");
expected.put("c", "three");
expected.put("c", "four");
verify(listener).beginVCard();
verify(listener).readProperty(null, "prop", expected, VCardDataType.TEXT, JCardValue.single("value"));
verifyNoMoreInteractions(listener);
}
use of ezvcard.io.json.JCardRawReader.JCardDataStreamListener in project ez-vcard by mangstadt.
the class JCardRawReaderTest method bad_snytax.
@Test
public void bad_snytax() throws Throwable {
// @formatter:off
String json = "[" + "[\"vcard\"," + "[" + "[\"prop1\", {}, \"text\", \"one\"]," + "[\"prop2\", {}, []]" + "]" + "]," + "[\"vcard\"," + "[" + "[\"prop1\", {}, \"text\", \"one\"]," + "[\"prop2\", {}, \"integer\", 2]" + "]" + "]" + "]";
// @formatter:on
JCardRawReader reader = createReader(json);
JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
try {
reader.readNext(listener);
fail("JCardParseException expected.");
} catch (JCardParseException e) {
assertEquals(JsonToken.VALUE_STRING, e.getExpectedToken());
assertEquals(JsonToken.START_ARRAY, e.getActualToken());
}
reader.readNext(listener);
verify(listener, times(2)).beginVCard();
verify(listener, times(2)).readProperty(null, "prop1", new VCardParameters(), VCardDataType.TEXT, JCardValue.single("one"));
verify(listener).readProperty(null, "prop2", new VCardParameters(), VCardDataType.INTEGER, JCardValue.single(2L));
verifyNoMoreInteractions(listener);
}
use of ezvcard.io.json.JCardRawReader.JCardDataStreamListener in project ez-vcard by mangstadt.
the class JCardRawReaderTest method different_data_types.
@Test
public void different_data_types() throws Throwable {
// @formatter:off
String json = "[\"vcard\"," + "[" + "[\"prop\", {}, \"text\", false, true, 1.1, 1, null, \"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.multi(false, true, 1.1, 1L, null, "text"));
verifyNoMoreInteractions(listener);
}
Aggregations