/*
 * 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.officeimporter.internal;

import java.util.Properties;

import org.apache.velocity.VelocityContext;
import org.jmock.Expectations;
import org.junit.Assert;
import org.junit.Test;
import org.xwiki.configuration.ConfigurationSource;
import org.xwiki.context.Execution;
import org.xwiki.context.ExecutionContext;
import org.xwiki.script.service.ScriptService;
import org.xwiki.test.jmock.AbstractComponentTestCase;
import org.xwiki.velocity.VelocityContextFactory;
import org.xwiki.velocity.VelocityContextInitializer;

/**
 * Integration tests for various {@link VelocityContextInitializer} implementations specific to the Office Importer
 * module.
 * 
 * @version $Id$
 * @since 1.9RC2
 */
public class VelocityContextInitializerTest extends AbstractComponentTestCase
{
    @Override
    protected void registerComponents() throws Exception
    {
        super.registerComponents();

        registerMockComponent(ScriptService.class, "officeimporter", "importer");
        registerMockComponent(ScriptService.class, "officemanager", "manager");
        final ConfigurationSource configurationSource = registerMockComponent(ConfigurationSource.class);
        getMockery().checking(new Expectations()
        {
            {
                oneOf(configurationSource).getProperty("logging.deprecated.enabled", true);
                will(returnValue(true));
                oneOf(configurationSource).getProperty("velocity.tools", Properties.class);
                will(returnValue(new Properties()));
            }
        });
    }

    /**
     * Test the presence of velocity bridges.
     * 
     * @throws Exception
     */
    @Test
    public void testVelocityBridges() throws Exception
    {
        // Make sure the execution context is not null when velocity bridges are initialized.
        getComponentManager().<Execution> getInstance(Execution.class).setContext(new ExecutionContext());

        VelocityContextFactory factory = getComponentManager().getInstance(VelocityContextFactory.class);
        VelocityContext context = factory.createContext();

        Assert.assertNotNull(context.get("officeimporter"));
        Assert.assertNotNull(context.get("ooconfig"));
        Assert.assertNotNull(context.get("oomanager"));
    }
}

@@ -935,38 +935,8 @@
 l;%0A%0A
-import java.util.Properties;%0A%0A
 impo
@@ -991,68 +991,24 @@
 rg.j
-mock.Expectations;%0Aimport org.junit.Assert;%0Aimport org.junit
+unit.jupiter.api
 .Tes
@@ -1214,39 +1214,200 @@
 est.
-jmock.AbstractComponentTestCase
+annotation.AllComponents;%0Aimport org.xwiki.test.junit5.mockito.ComponentTest;%0Aimport org.xwiki.test.junit5.mockito.InjectComponentManager;%0Aimport org.xwiki.test.mockito.MockitoComponentManager
 ;%0Aim
@@ -1509,16 +1509,119 @@
 lizer;%0A%0A
+import static org.junit.jupiter.api.Assertions.assertNotNull;%0Aimport static org.mockito.Mockito.when;%0A%0A
 /**%0A * I
@@ -1785,23 +1785,46 @@
 RC2%0A */%0A
-public 
+@ComponentTest%0A@AllComponents%0A
 class Ve
@@ -1855,167 +1855,279 @@
 Test
- extends AbstractComponentTestCase%0A%7B%0A    @Override%0A    protected void registerComponents() throws Exception%0A    %7B%0A        super.registerComponents();%0A%0A        
+%0A%7B%0A    @InjectComponentManager%0A    private MockitoComponentManager componentManager;%0A%0A    /**%0A     * Test the presence of velocity bridges.%0A     * %0A     * @throws Exception%0A     */%0A    @Test%0A    void velocityBridges() throws Exception%0A    %7B%0A        this.componentManager.
 regi
@@ -2185,31 +2185,41 @@
 ter%22
-, %22importer%22);%0A        
+);%0A        this.componentManager.
 regi
@@ -2276,19 +2276,8 @@
 ger%22
-, %22manager%22
 );%0A 
@@ -2287,14 +2287,8 @@
     
-final 
 Conf
@@ -2307,30 +2307,39 @@
 rce 
-configurationSource = 
+source = this.componentManager.
 regi
@@ -2396,115 +2396,19 @@
     
-getMockery().checking(new Expectations()%0A        %7B%0A            %7B%0A                oneOf(configurationS
+when(s
 ource
-)
 .get
@@ -2455,394 +2455,28 @@
 rue)
-;%0A                will(returnValue(true));%0A                oneOf(configurationSource).getProperty(%22velocity.tools%22, Properties.class);%0A                will(returnValue(new Properties()));%0A            %7D%0A        %7D);%0A    %7D%0A%0A    /**%0A     * Test the presence of velocity bridges.%0A     * %0A     * @throws Exception%0A     */%0A    @Test%0A    public void testVelocityBridges() throws Exception%0A    %7B
+).thenReturn(true);%0A
 %0A   
@@ -2574,20 +2574,22 @@
         
-getC
+this.c
 omponent
@@ -2595,18 +2595,16 @@
 tManager
-()
 .%3CExecut
@@ -2607,17 +2607,16 @@
 ecution%3E
- 
 getInsta
@@ -2718,12 +2718,14 @@
 y = 
-getC
+this.c
 ompo
@@ -2735,18 +2735,16 @@
 tManager
-()
 .getInst
@@ -2839,39 +2839,32 @@
 ext();%0A%0A        
-Assert.
 assertNotNull(co
@@ -2893,39 +2893,32 @@
 ter%22));%0A        
-Assert.
 assertNotNull(co
@@ -2953,15 +2953,8 @@
     
-Assert.
 asse

Fix failing test + convert to JUnit5/Mockito * TODO: find out why suddenly it was failing