/*
 * 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.macro.chart.source.table;

import org.jmock.Expectations;
import org.xwiki.component.internal.RootComponentManager;
import org.xwiki.rendering.block.XDOM;
import org.xwiki.rendering.internal.parser.reference.URLResourceReferenceTypeParser;
import org.xwiki.rendering.internal.parser.xwiki20.XWiki20ImageReferenceParser;
import org.xwiki.rendering.internal.parser.xwiki20.XWiki20LinkReferenceParser;
import org.xwiki.rendering.internal.parser.xwiki20.XWiki20Parser;
import org.xwiki.rendering.internal.renderer.DefaultLinkLabelGenerator;
import org.xwiki.rendering.internal.renderer.plain.PlainTextBlockRenderer;
import org.xwiki.rendering.internal.renderer.plain.PlainTextRenderer;
import org.xwiki.rendering.internal.renderer.plain.PlainTextRendererFactory;
import org.xwiki.rendering.macro.MacroContentParser;
import org.xwiki.rendering.parser.Parser;
import org.xwiki.rendering.syntax.Syntax;
import org.xwiki.test.AbstractMockingComponentTestCase;

import java.io.StringReader;
import java.util.Map;
import java.util.HashMap;

import org.xwiki.component.manager.ComponentManager;
import org.xwiki.test.annotation.ComponentList;
import org.xwiki.test.annotation.MockingRequirement;

import org.xwiki.rendering.renderer.BlockRenderer;

/**
 * Helper to write unit tests for Table-based data sources.
 *
 * @version $Id$
 * @since 4.2M1
 */
@ComponentList({
    PlainTextBlockRenderer.class,
    PlainTextRendererFactory.class,
    RootComponentManager.class,
    XWiki20Parser.class,
    XWiki20LinkReferenceParser.class,
    URLResourceReferenceTypeParser.class,
    XWiki20ImageReferenceParser.class,
    PlainTextRenderer.class,
    DefaultLinkLabelGenerator.class
})
public abstract class AbstractMacroContentTableBlockDataSourceTest extends AbstractMockingComponentTestCase
{
    @MockingRequirement(exceptions={ComponentManager.class, BlockRenderer.class})
    private MacroContentTableBlockDataSource source;

    protected MacroContentTableBlockDataSource getDataSource()
    {
        return this.source;
    }

    protected Map<String, String> map(String... keyValues)
    {
        Map<String, String> map = new HashMap<String, String>();

        for (int i = 0; i < keyValues.length; i += 2) {
            map.put(keyValues[i], keyValues[i + 1]);
        }

        return map;
    }

    protected void setUpContentExpectation(final String macroContent) throws Exception
    {
        final MacroContentParser parser = getComponentManager().getInstance(MacroContentParser.class);

        // In order to make it easy to write unit tests, we allow tests to pass a string written in XWiki/2.0 synyax
        // which we then parser to generate an XDOM that we use in the expectation.
        final XDOM expectedXDOM = getComponentManager().<Parser>getInstance(Parser.class,
            Syntax.XWIKI_2_0.toIdString()).parse(new StringReader(macroContent));

        getMockery().checking(new Expectations() {{
            // Simulate parsing the macro content that returns a XDOM not containing a table
            oneOf(parser).parse(macroContent, null, true, false);
                will(returnValue(expectedXDOM));
        }});
    }
}

@@ -947,24 +947,102 @@
 rce.table;%0A%0A
+import java.io.StringReader;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 import org.j
@@ -1091,21 +1091,16 @@
 ent.
-internal.Root
+manager.
 Comp
@@ -1843,32 +1843,83 @@
 .parser.Parser;%0A
+import org.xwiki.rendering.renderer.BlockRenderer;%0A
 import org.xwiki
@@ -2003,140 +2003,8 @@
 ase;
-%0A%0Aimport java.io.StringReader;%0Aimport java.util.Map;%0Aimport java.util.HashMap;%0A%0Aimport org.xwiki.component.manager.ComponentManager;
 %0Aimp
@@ -2106,60 +2106,8 @@
 t;%0A%0A
-import org.xwiki.rendering.renderer.BlockRenderer;%0A%0A
 /**%0A
@@ -2297,40 +2297,8 @@
 ss,%0A
-    RootComponentManager.class,%0A
     

Fix test