/*
 * 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.rest.internal.url.resources;

import java.net.URL;
import java.util.Locale;

import javax.inject.Provider;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.test.junit5.mockito.ComponentTest;
import org.xwiki.test.junit5.mockito.InjectMockComponents;

import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.web.XWikiURLFactory;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
 * Unit tests for {@link DocumentRestURLGenerator}.
 *
 * @version $Id$
 * @since 10.4RC1
 */
@ComponentTest
public class DocumentRestURLGeneratorTest
{
    @InjectMockComponents
    private DocumentRestURLGenerator generator;

    @BeforeEach
    public void setup(ComponentManager componentManager) throws Exception
    {
        Provider<XWikiContext> xwikiContextProvider = componentManager.getInstance(XWikiContext.TYPE_PROVIDER);
        XWikiContext xwikiContext = xwikiContextProvider.get();
        XWiki xwiki = mock(XWiki.class);
        XWikiURLFactory urlFactory = mock(XWikiURLFactory.class);

        when(xwikiContext.getWiki()).thenReturn(xwiki);
        when(xwikiContext.getURLFactory()).thenReturn(urlFactory);
        when(xwiki.getWebAppPath(xwikiContext)).thenReturn("/");
        when(urlFactory.getServerURL(xwikiContext)).thenReturn(new URL("http://localhost"));
    }

    @Test
    public void getURLWithoutLocale() throws Exception
    {
        DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
        assertEquals("http://localhost/rest/wikis/wiki/spaces/space/pages/page",
            this.generator.getURL(documentReference).toString());
    }

    @Test
    public void getURLWithLocale() throws Exception
    {
        DocumentReference documentReference = new DocumentReference("wiki", "space", "page", Locale.FRENCH);
        assertEquals("http://localhost/rest/wikis/wiki/spaces/space/pages/page/translations/fr",
            this.generator.getURL(documentReference).toString());
    }

    @Test
    public void getURLWithSlash() throws Exception
    {
        DocumentReference documentReference = new DocumentReference("wiki", "space", "pa/ge");
        assertEquals("http://localhost/rest/wikis/wiki/spaces/space/pages/pa%2Fge",
            this.generator.getURL(documentReference).toString());
    }
}

@@ -1440,14 +1440,30 @@
 nit.
+jupiter.api.
 Assert
+ions
 .ass
@@ -1667,23 +1667,16 @@
 entTest%0A
-public 
 class Do
@@ -1702,16 +1702,16 @@
 torTest%0A
+
 %7B%0A    @I
@@ -1795,31 +1795,24 @@
 oreEach%0A    
-public 
 void setup(C
@@ -2446,39 +2446,32 @@
 %0A%0A    @Test%0A    
-public 
 void getURLWitho
@@ -2758,39 +2758,32 @@
 %0A%0A    @Test%0A    
-public 
 void getURLWithL
@@ -3106,19 +3106,12 @@
 est%0A
+
     
-public 
 void

Fix mix of JUnit4 and JUnit5 + apply best practices