/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.rendering.internal.syntax;

import org.jmock.Expectations;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.xwiki.properties.converter.Converter;
import org.xwiki.rendering.syntax.Syntax;
import org.xwiki.rendering.syntax.SyntaxFactory;
import org.xwiki.test.AbstractMockingComponentTestCase;
import org.xwiki.test.annotation.MockingRequirement;

/**
 * Unit tests for {@link SyntaxConverter}.
 *
 * @version $Id$
 * @since 4.2M3
 */
@MockingRequirement(SyntaxConverter.class)
public class SyntaxConverterTest extends AbstractMockingComponentTestCase
{
    private Converter converter;

    @Before
    public void configure() throws Exception
    {
        this.converter = getComponentManager().getInstance(Converter.class, Syntax.class.getName());
    }

    @Test
    public void convertToSyntaxObject() throws Exception
    {
        final SyntaxFactory factory = getComponentManager().getInstance(SyntaxFactory.class);
        getMockery().checking(new Expectations()
        {
            {
                oneOf(factory).createSyntaxFromIdString("xwiki/2.1");
                will(returnValue(Syntax.XWIKI_2_1));
            }
        });

        Syntax syntax = this.converter.convert(Syntax.class, "xwiki/2.1");
        Assert.assertEquals(Syntax.XWIKI_2_1, syntax);
    }

    @Test
    public void convertToSyntaxObjectWhenNull() throws Exception
    {
        Syntax syntax = this.converter.convert(Syntax.class, null);
        Assert.assertNull(syntax);
    }

    @Test
    public void convertToString() throws Exception
    {
        String syntaxId = this.converter.convert(String.class, Syntax.XWIKI_2_1);
        Assert.assertEquals(Syntax.XWIKI_2_1.toIdString(), syntaxId);
    }

    @Test
    public void convertToStringWhenNull() throws Exception
    {
        String syntaxId = this.converter.convert(String.class, null);
        Assert.assertNull(syntaxId);
    }
}

@@ -1081,19 +1081,128 @@
 r.Conver
-ter
+sionException;%0Aimport org.xwiki.properties.converter.Converter;%0Aimport org.xwiki.rendering.parser.ParseException
 ;%0Aimport
@@ -2326,32 +2326,752 @@
 syntax);%0A    %7D%0A%0A
+    @Test%0A    public void convertToSyntaxObjectWhenUnknownSyntax() throws Exception%0A    %7B%0A        final SyntaxFactory factory = getComponentManager().getInstance(SyntaxFactory.class);%0A        getMockery().checking(new Expectations()%0A        %7B%0A            %7B%0A                oneOf(factory).createSyntaxFromIdString(%22invalid%22);%0A                will(throwException(new ParseException(%22invalid syntax%22)));%0A            %7D%0A        %7D);%0A%0A        try %7B%0A            this.converter.convert(Syntax.class, %22invalid%22);%0A            Assert.fail(%22Should have thrown ConversionException%22);%0A        %7D catch (ConversionException expected) %7B%0A            Assert.assertEquals(%22Unknown syntax %5Binvalid%5D%22, expected.getMessage());%0A        %7D%0A    %7D%0A%0A
     @Test%0A    pu

Add a Content macro to be able to mix content in different syntaxes * Add one more test (thanks to Sergiu for the idea)