/*
 * (C) Copyright 2016 Boni Garcia (http://bonigarcia.github.io/)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package io.github.bonigarcia.wdm.test.base;

import static io.github.bonigarcia.wdm.config.Architecture.DEFAULT;
import static java.lang.invoke.MethodHandles.lookup;
import static org.assertj.core.api.Assertions.assertThat;
import static org.slf4j.LoggerFactory.getLogger;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;

import io.github.bonigarcia.wdm.WebDriverManager;
import io.github.bonigarcia.wdm.config.Architecture;
import io.github.bonigarcia.wdm.config.OperatingSystem;

/**
 * Parent class for version based tests.
 *
 * @author Boni Garcia
 * @since 1.4.1
 */
abstract public class VersionTestParent {

    protected Class<? extends WebDriver> driverClass;
    protected String[] specificVersions;
    protected OperatingSystem os;

    final Logger log = getLogger(lookup().lookupClass());

    @ParameterizedTest
    @EnumSource(names = { "DEFAULT", "X32", "X64" })
    void testLatestVersion(Architecture architecture) throws Exception {
        WebDriverManager wdm = WebDriverManager.getInstance(driverClass);

        String osLabel = "";
        if (os != null) {
            wdm.operatingSystem(os);
            osLabel = " os=" + os;
        }
        log.debug("Test latest {} [arch={}{}]", wdm.getDriverManagerType(),
                architecture, osLabel);

        switch (architecture) {
        case X32:
            wdm.arch32().setup();
            break;
        case X64:
            wdm.arch64().setup();
            break;
        default:
            wdm.setup();
        }

        assertThat(wdm.getDownloadedDriverVersion()).isNotNull();
    }

    @ParameterizedTest
    @EnumSource(names = { "DEFAULT", "X32", "X64" })
    void testSpecificVersions(Architecture architecture) throws Exception {
        WebDriverManager wdm = WebDriverManager.getInstance(driverClass);

        for (String specificVersion : specificVersions) {
            if (architecture != DEFAULT) {
                wdm = wdm.architecture(architecture);
            }
            String osLabel = "";
            if (os != null) {
                wdm = wdm.operatingSystem(os);
                osLabel = " os=" + os;
            }
            log.debug("Test {} version={} [arch={}{}]",
                    wdm.getDriverManagerType(), specificVersion, architecture,
                    osLabel);

            wdm.driverVersion(specificVersion).setup();

            assertThat(wdm.getDownloadedDriverVersion())
                    .isEqualTo(specificVersion);
        }
    }

}

@@ -1835,24 +1835,30 @@
 %0A           
+ wdm =
  wdm.operati
@@ -1863,32 +1863,32 @@
 tingSystem(os);%0A
-
             osLa
@@ -1908,32 +1908,132 @@
 + os;%0A        %7D%0A
+        if (architecture != DEFAULT) %7B%0A            wdm = wdm.architecture(architecture);%0A        %7D%0A%0A
         log.debu
@@ -2136,204 +2136,8 @@
 l);%0A
-%0A        switch (architecture) %7B%0A        case X32:%0A            wdm.arch32().setup();%0A            break;%0A        case X64:%0A            wdm.arch64().setup();%0A            break;%0A        default:%0A    
     
@@ -2152,26 +2152,16 @@
 setup();
-%0A        %7D
 %0A%0A      
@@ -2508,24 +2508,25 @@
 Versions) %7B%0A
+%0A
             
@@ -2779,32 +2779,87 @@
 ;%0A            %7D%0A
+            wdm = wdm.driverVersion(specificVersion);%0A%0A
             log.
@@ -3007,17 +3007,16 @@
 Label);%0A
-%0A
         
@@ -3027,39 +3027,8 @@
 wdm.
-driverVersion(specificVersion).
 setu

Refactor logic of parent class for versions test