/*
 * (C) Copyright 2021 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.versions;

import static java.lang.invoke.MethodHandles.lookup;
import static org.assertj.core.api.Assertions.assertThat;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.Optional;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;

import io.github.bonigarcia.wdm.config.Config;
import io.github.bonigarcia.wdm.online.HttpClient;
import io.github.bonigarcia.wdm.versions.VersionDetector;

/**
 * Commands database test.
 *
 * @author Boni Garcia (boni.gg@gmail.com)
 * @since 4.4.0
 */
class BrowserVersionDetectionTest {

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

    @Test
    void commandsTest() throws Exception {
        Config config = new Config();
        HttpClient httpClient = new HttpClient(config);
        VersionDetector versionDetector = new VersionDetector(config,
                httpClient);
        String[] browsers = { "chrome", "firefox", "edge", "opera",
                "chromium" };
        for (String browser : browsers) {
            Optional<String> detectedVersion = versionDetector
                    .getBrowserVersionFromTheShell(browser);
            if (detectedVersion.isPresent()) {
                log.debug("The detected version of {} is {}", browser,
                        detectedVersion.get());
                int numericVersion = Integer.parseInt(detectedVersion.get());
                assertThat(numericVersion).isPositive();
            }
        }

    }

}

@@ -784,16 +784,86 @@
 rtThat;%0A
+import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;%0A
 import s
@@ -961,20 +961,173 @@
 ter.api.
-Test
+BeforeAll;%0Aimport org.junit.jupiter.api.TestInstance;%0Aimport org.junit.jupiter.params.ParameterizedTest;%0Aimport org.junit.jupiter.params.provider.ValueSource
 ;%0Aimport
@@ -1400,16 +1400,41 @@
 4.0%0A */%0A
+@TestInstance(PER_CLASS)%0A
 class Br
@@ -1529,54 +1529,78 @@
     
-@Test%0A    void commandsTest() throws Exception
+VersionDetector versionDetector;%0A%0A    @BeforeAll%0A    void setupClass()
  %7B%0A 
@@ -1700,32 +1700,16 @@
         
-VersionDetector 
 versionD
@@ -1745,32 +1745,16 @@
 (config,
-%0A               
  httpCli
@@ -1767,28 +1767,57 @@
     
+%7D%0A%0A
     
-String%5B%5D browser
+@ParameterizedTest%0A    @ValueSource(string
 s = 
@@ -1855,32 +1855,16 @@
 %22opera%22,
-%0A               
  %22chromi
@@ -1872,56 +1872,67 @@
 m%22 %7D
-;
+)
 %0A    
-    for (String browser : browsers) %7B%0A    
+void commandsTest(String browser) throws Exception %7B%0A
     
@@ -2002,20 +2002,16 @@
         
-    
 .getBrow
@@ -2051,20 +2051,16 @@
         
-  
-  
 if (dete
@@ -2082,28 +2082,24 @@
 resent()) %7B%0A
-    
             
@@ -2173,20 +2173,16 @@
         
-    
 detected
@@ -2209,20 +2209,16 @@
         
- 
-   
 int nume
@@ -2283,20 +2283,16 @@
         
-    
 assertTh
@@ -2336,24 +2336,9 @@
     
-    %7D%0A        %7D%0A
+%7D
 %0A   

Convert test in parameterized