Search in sources :

Example 11 with SyntaxStyle

use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.

the class VObjectReaderTest method blank_parameter_name.

/**
 * When a parameter name is empty.
 */
@Test
public void blank_parameter_name() throws Exception {
    // @formatter:off
    String string = "PROP;=value:value";
    for (SyntaxStyle style : SyntaxStyle.values()) {
        VObjectReader reader = reader(string, style);
        VObjectDataListenerMock listener = spy(new VObjectDataListenerMock());
        reader.parse(listener);
        InOrder inorder = inOrder(listener);
        inorder.verify(listener).onProperty(eq(property().name("PROP").param("", "value").value("value").build()), any(Context.class));
        // @formatter:off
        String[] lines = string.split("\r\n");
        int line = 0;
        assertContexts(listener, context(lines[line], ++line));
    // @formatter:on
    }
}
Also used : InOrder(org.mockito.InOrder) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) Test(org.junit.Test)

Example 12 with SyntaxStyle

use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.

the class VObjectReaderTest method no_parameter_name.

/**
 * When a parameter value doesn't have a name.
 */
@Test
public void no_parameter_name() throws Exception {
    // @formatter:off
    String string = "PROP;HOME;WORK:value";
    for (SyntaxStyle style : SyntaxStyle.values()) {
        VObjectReader reader = reader(string, style);
        VObjectDataListenerMock listener = spy(new VObjectDataListenerMock());
        reader.parse(listener);
        InOrder inorder = inOrder(listener);
        inorder.verify(listener).onProperty(eq(property().name("PROP").param(null, "HOME", "WORK").value("value").build()), any(Context.class));
        // @formatter:off
        String[] lines = string.split("\r\n");
        int line = 0;
        assertContexts(listener, context(lines[line], ++line));
    // @formatter:on
    }
}
Also used : InOrder(org.mockito.InOrder) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) Test(org.junit.Test)

Example 13 with SyntaxStyle

use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.

the class VObjectReaderTest method whitespace_around_component_names.

/**
 * When checking for BEGIN and END properties, the property name and value
 * should be trimmed so that any whitespace around the colon ignored.
 * Whitespace around the colon is allowed by old style syntax, though it
 * never happens in practice.
 */
@Test
public void whitespace_around_component_names() throws Exception {
    // @formatter:off
    String string = "BEGIN:COMP1\r\n" + "BEGIN:COMP2\r\n" + "END : COMP2 \r\n" + "END\t:\tCOMP1\t";
    for (SyntaxStyle style : SyntaxStyle.values()) {
        VObjectReader reader = reader(string, style);
        VObjectDataListenerMock listener = spy(new VObjectDataListenerMock());
        reader.parse(listener);
        InOrder inorder = inOrder(listener);
        inorder.verify(listener).onComponentBegin(eq("COMP1"), any(Context.class));
        inorder.verify(listener).onComponentBegin(eq("COMP2"), any(Context.class));
        inorder.verify(listener).onComponentEnd(eq("COMP2"), any(Context.class));
        inorder.verify(listener).onComponentEnd(eq("COMP1"), any(Context.class));
        // @formatter:off
        String[] lines = string.split("\r\n");
        int line = 0;
        assertContexts(listener, context(lines[line], ++line), context(asList("COMP1"), lines[line], ++line), context(asList("COMP1"), lines[line], ++line), context(lines[line], ++line));
    // @formatter:on
    }
}
Also used : InOrder(org.mockito.InOrder) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) Test(org.junit.Test)

Example 14 with SyntaxStyle

use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.

the class VObjectWriterTest method parameters_multivalued_empty_values.

/**
 * When the parameters multimap has a key with an empty list, the parameter
 * should not be written. This should never happen if the user sticks to the
 * API of the VObjectParameters class and does not modify the backing map
 * manually.
 */
@Test
public void parameters_multivalued_empty_values() throws Exception {
    for (SyntaxStyle style : SyntaxStyle.values()) {
        for (boolean caretEncoding : new boolean[] { false, true }) {
            StringWriter sw = new StringWriter();
            VObjectWriter writer = new VObjectWriter(sw, style);
            writer.setCaretEncodingEnabled(caretEncoding);
            VObjectParameters parameters = new VObjectParameters();
            parameters.getMap().put("PARAM", new ArrayList<String>());
            writer.writeProperty(null, "PROP", parameters, "");
            String actual = sw.toString();
            // @formatter:off
            String expected = "PROP:\r\n";
            // @formatter:on
            assertEquals(expected, actual);
        }
    }
}
Also used : StringWriter(java.io.StringWriter) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) VObjectParameters(com.github.mangstadt.vinnie.VObjectParameters) Test(org.junit.Test)

Example 15 with SyntaxStyle

use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.

the class VObjectWriterTest method property_name.

@Test
public void property_name() throws Exception {
    for (SyntaxStyle style : SyntaxStyle.values()) {
        StringWriter sw = new StringWriter();
        VObjectWriter writer = new VObjectWriter(sw, style);
        writer.writeProperty(null, "PROP", new VObjectParameters(), "");
        try {
            writer.writeProperty(null, "", new VObjectParameters(), "");
            fail("IllegalArgumentException expected when property name is empty and style is " + style.name());
        } catch (IllegalArgumentException e) {
        // expected
        }
        try {
            writer.writeProperty(null, null, new VObjectParameters(), "");
            fail("NullPointerException expected when property name is null and style is " + style.name());
        } catch (NullPointerException e) {
        // expected
        }
        String actual = sw.toString();
        // @formatter:off
        String expected = "PROP:\r\n";
        // @formatter:on
        assertEquals(expected, actual);
    }
}
Also used : StringWriter(java.io.StringWriter) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) VObjectParameters(com.github.mangstadt.vinnie.VObjectParameters) Test(org.junit.Test)

Aggregations

SyntaxStyle (com.github.mangstadt.vinnie.SyntaxStyle)50 Test (org.junit.Test)45 InOrder (org.mockito.InOrder)24 StringWriter (java.io.StringWriter)21 VObjectParameters (com.github.mangstadt.vinnie.VObjectParameters)15 VObjectProperty (com.github.mangstadt.vinnie.VObjectProperty)12 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)7 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)7 DecoderException (com.github.mangstadt.vinnie.codec.DecoderException)6 ArrayList (java.util.ArrayList)4 AllowedCharacters (com.github.mangstadt.vinnie.validate.AllowedCharacters)3 ValidationWarning (ezvcard.ValidationWarning)3 HashMap (java.util.HashMap)3 Map (java.util.Map)2 VCardDataType (ezvcard.VCardDataType)1 VCardVersion (ezvcard.VCardVersion)1 ClientPidMap (ezvcard.property.ClientPidMap)1 SortString (ezvcard.property.SortString)1 AbstractList (java.util.AbstractList)1 EnumSet (java.util.EnumSet)1