use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.
the class JCardRawReaderTest method data_type_unrecognized.
@Test
public void data_type_unrecognized() throws Throwable {
// @formatter:off
String json = "[\"vcard\"," + "[" + "[\"prop\", {}, \"foo\", \"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(), VCardDataType.get("foo"), JCardValue.single("value"));
verifyNoMoreInteractions(listener);
}
use of ezvcard.parameter.VCardParameters 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.parameter.VCardParameters 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.parameter.VCardParameters 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.parameter.VCardParameters 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);
}
Aggregations