/*
 * 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.test.docker.internal.junit5;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.xwiki.test.docker.junit5.TestConfiguration;
import org.xwiki.test.docker.junit5.UITest;
import org.xwiki.test.docker.junit5.servletengine.ServletEngine;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * Unit tests for {@link TestConfiguration}.
 *
 * @version $Id$
 */
public class TestConfigurationTest
{
    @UITest
    public class EmptyAnnotation
    {
    }

    @UITest(servletEngine = ServletEngine.TOMCAT, verbose = true, databaseTag = "version")
    public class SampleAnnotation
    {
    }

    @BeforeEach
    public void setUp()
    {
        System.clearProperty("xwiki.test.ui.servletEngine");
        System.clearProperty("xwiki.test.ui.verbose");
        System.clearProperty("xwiki.test.ui.databaseTag");
    }

    @Test
    public void getConfigurationWhenDefault()
    {
        UITest uiTest = EmptyAnnotation.class.getAnnotation(UITest.class);

        TestConfiguration configuration = new TestConfiguration(uiTest);
        assertEquals(ServletEngine.JETTY_STANDALONE, configuration.getServletEngine());
        assertFalse(configuration.isVerbose());
        assertNull(configuration.getDatabaseTag());
    }

    @Test
    public void getConfigurationWhenInAnnotationAndNoSystemProperty()
    {
        UITest uiTest = SampleAnnotation.class.getAnnotation(UITest.class);

        TestConfiguration configuration = new TestConfiguration(uiTest);
        assertEquals(ServletEngine.TOMCAT, configuration.getServletEngine());
        assertTrue(configuration.isVerbose());
        assertEquals("version", configuration.getDatabaseTag());
    }

    @Test
    public void getConfigurationWhenInSystemPropertiesAndNotInAnnotation()
    {
        UITest uiTest = EmptyAnnotation.class.getAnnotation(UITest.class);
        System.setProperty("xwiki.test.ui.servletEngine", "jetty");
        System.setProperty("xwiki.test.ui.verbose", "true");
        System.setProperty("xwiki.test.ui.databaseTag", "version");

        TestConfiguration configuration = new TestConfiguration(uiTest);
        assertEquals(ServletEngine.JETTY, configuration.getServletEngine());
        assertTrue(configuration.isVerbose());
        assertEquals("version", configuration.getDatabaseTag());
    }

    @Test
    public void getConfigurationWhenInSystemPropertiesAndInAnnotation()
    {
        UITest uiTest = SampleAnnotation.class.getAnnotation(UITest.class);
        System.setProperty("xwiki.test.ui.servletEngine", "jetty");
        System.setProperty("xwiki.test.ui.verbose", "true");
        System.setProperty("xwiki.test.ui.databaseTag", "otherversion");

        // System properties win!
        TestConfiguration configuration = new TestConfiguration(uiTest);
        assertEquals(ServletEngine.JETTY, configuration.getServletEngine());
        assertTrue(configuration.isVerbose());
        assertEquals("otherversion", configuration.getDatabaseTag());
    }
}

@@ -1106,24 +1106,132 @@
 it5.UITest;%0A
+import org.xwiki.test.docker.junit5.browser.Browser;%0Aimport org.xwiki.test.docker.junit5.database.Database;%0A
 import org.x
@@ -1349,68 +1349,8 @@
 ls;%0A
-import static org.junit.jupiter.api.Assertions.assertFalse;%0A
 impo
@@ -1537,23 +1537,16 @@
 Id$%0A */%0A
-public 
 class Te
@@ -1579,31 +1579,24 @@
 @UITest%0A    
-public 
 class EmptyA
@@ -1713,23 +1713,16 @@
 n%22)%0A    
-public 
 class Sa
@@ -1765,31 +1765,24 @@
 oreEach%0A    
-public 
 void setUp()
@@ -1976,39 +1976,32 @@
 %0A%0A    @Test%0A    
-public 
 void getConfigur
@@ -2280,37 +2280,190 @@
 sert
-False(configuration.isVerbose
+Equals(Browser.FIREFOX, configuration.getBrowser());%0A        assertEquals(Database.HSQLDB_EMBEDDED, configuration.getDatabase());%0A        assertNull(configuration.getServletEngineTag
 ());
@@ -2528,39 +2528,32 @@
 %0A%0A    @Test%0A    
-public 
 void getConfigur
@@ -2954,39 +2954,32 @@
 %0A%0A    @Test%0A    
-public 
 void getConfigur
@@ -3592,15 +3592,8 @@
     
-public 
 void

Fix test on CI (BTW this is why I hate static methods, yet I've fallen in the trap of using some, I now need the time to refactor that and remove the static classes) + remove "public" keyword to follow test best practices