Search in sources :

Example 6 with JCardDataStreamListener

use of ezvcard.io.json.JCardRawReader.JCardDataStreamListener in project ez-vcard by mangstadt.

the class JCardRawReaderTest method ignore_other_json.

@Test
public void ignore_other_json() throws Throwable {
    // @formatter:off
    String json = "{" + "\"website\": \"example.com\"," + "\"vcard\":" + "[\"vcard\"," + "[" + "[\"prop\", {}, \"text\", \"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.TEXT, JCardValue.single("value"));
    verifyNoMoreInteractions(listener);
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) JCardDataStreamListener(ezvcard.io.json.JCardRawReader.JCardDataStreamListener) Test(org.junit.Test)

Example 7 with JCardDataStreamListener

use of ezvcard.io.json.JCardRawReader.JCardDataStreamListener in project ez-vcard by mangstadt.

the class JCardRawReaderTest method group.

@Test
public void group() throws Throwable {
    // @formatter:off
    String json = "[\"vcard\"," + "[" + "[\"prop\", { \"group\": \"one\" }, \"text\", \"value\"]" + "]" + "]";
    // @formatter:on
    JCardRawReader reader = createReader(json);
    JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
    reader.readNext(listener);
    verify(listener).beginVCard();
    verify(listener).readProperty("one", "prop", new VCardParameters(), VCardDataType.TEXT, JCardValue.single("value"));
    verifyNoMoreInteractions(listener);
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) JCardDataStreamListener(ezvcard.io.json.JCardRawReader.JCardDataStreamListener) Test(org.junit.Test)

Example 8 with JCardDataStreamListener

use of ezvcard.io.json.JCardRawReader.JCardDataStreamListener in project ez-vcard by mangstadt.

the class JCardRawReaderTest method empty.

@Test
public void empty() throws Throwable {
    // @formatter:off
    String json = "";
    // @formatter:on
    JCardRawReader reader = createReader(json);
    JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
    reader.readNext(listener);
    verify(listener, never()).beginVCard();
    verifyNoMoreInteractions(listener);
}
Also used : JCardDataStreamListener(ezvcard.io.json.JCardRawReader.JCardDataStreamListener) Test(org.junit.Test)

Example 9 with JCardDataStreamListener

use of ezvcard.io.json.JCardRawReader.JCardDataStreamListener in project ez-vcard by mangstadt.

the class JCardRawReaderTest method no_vcard.

@Test
public void no_vcard() throws Throwable {
    // @formatter:off
    String json = "{" + "\"foo\": \"bar\"" + "}";
    // @formatter:on
    JCardRawReader reader = createReader(json);
    JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
    reader.readNext(listener);
    verify(listener, never()).beginVCard();
    verifyNoMoreInteractions(listener);
}
Also used : JCardDataStreamListener(ezvcard.io.json.JCardRawReader.JCardDataStreamListener) Test(org.junit.Test)

Example 10 with JCardDataStreamListener

use of ezvcard.io.json.JCardRawReader.JCardDataStreamListener 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);
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) JCardDataStreamListener(ezvcard.io.json.JCardRawReader.JCardDataStreamListener) Test(org.junit.Test)

Aggregations

JCardDataStreamListener (ezvcard.io.json.JCardRawReader.JCardDataStreamListener)15 Test (org.junit.Test)15 VCardParameters (ezvcard.parameter.VCardParameters)12 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1