/*
 * 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 java.util.Arrays;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.xwiki.properties.converter.ConversionException;
import org.xwiki.properties.converter.Converter;
import org.xwiki.rendering.parser.ParseException;
import org.xwiki.rendering.syntax.Syntax;
import org.xwiki.test.annotation.BeforeComponent;
import org.xwiki.test.annotation.ComponentList;
import org.xwiki.test.mockito.MockitoComponentMockingRule;

import static org.mockito.Mockito.when;

/**
 * Unit tests for {@link DeprecatedSyntaxConverter}.
 * 
 * @version $Id$
 */
@ComponentList(SyntaxConverter.class)
public class DeprecatedSyntaxConverterTest
{
    @Rule
    public MockitoComponentMockingRule<Converter> mocker =
        new MockitoComponentMockingRule<Converter>(DeprecatedSyntaxConverter.class, Arrays.asList(Converter.class));

    @BeforeComponent
    public void beforeComponent() throws Exception
    {
    }

    // Tests

    @Test
    public void convertToSyntaxObject() throws Exception
    {
        Syntax syntax = (Syntax) this.mocker.getComponentUnderTest().convert(Syntax.class, "xwiki/2.1");
        Assert.assertEquals(Syntax.XWIKI_2_1, syntax);
    }

    @Test
    public void convertToSyntaxObjectWhenUnknownSyntax() throws Exception
    {
        try {
            this.mocker.getComponentUnderTest().convert(Syntax.class, "invalid");
            Assert.fail("Should have thrown ConversionException");
        } catch (ConversionException expected) {
            Assert.assertEquals("Unknown syntax [invalid]", expected.getMessage());
        }
    }

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

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

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

@@ -937,59 +937,8 @@
 x;%0A%0A
-import java.util.Arrays;%0A%0Aimport org.junit.Assert;%0A
 impo
@@ -1091,58 +1091,8 @@
 er;%0A
-import org.xwiki.rendering.parser.ParseException;%0A
 impo
@@ -1309,28 +1309,113 @@
 org.
-mockito.Mockito.when
+junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertNull;%0Aimport static org.junit.Assert.fail
 ;%0A%0A/
@@ -1510,16 +1510,22 @@
 entList(
+%7B%0A    
 SyntaxCo
@@ -1537,16 +1537,51 @@
 er.class
+,%0A    DefaultSyntaxRegistry.class%0A%7D
 )%0Apublic
@@ -1728,25 +1728,16 @@
 ingRule%3C
-Converter
 %3E(Deprec
@@ -1765,40 +1765,8 @@
 lass
-, Arrays.asList(Converter.class)
 );%0A%0A
@@ -2042,39 +2042,32 @@
 /2.1%22);%0A        
-Assert.
 assertEquals(Syn
@@ -2295,23 +2295,16 @@
         
-Assert.
 fail(%22Sh
@@ -2396,39 +2396,32 @@
 ) %7B%0A            
-Assert.
 assertEquals(%22Un
@@ -2665,39 +2665,32 @@
  null);%0A        
-Assert.
 assertNull(synta
@@ -2883,31 +2883,24 @@
 1);%0A        
-Assert.
 assertEquals
@@ -3132,23 +3132,16 @@
         
-Assert.
 assertNu

Add concept of Syntax Registry * Fix test