/*
 * (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.cache;

import static io.github.bonigarcia.wdm.etc.Architecture.DEFAULT;
import static io.github.bonigarcia.wdm.etc.DriverManagerType.CHROME;
import static io.github.bonigarcia.wdm.etc.DriverManagerType.FIREFOX;
import static java.util.Arrays.asList;
import static org.apache.commons.io.FileUtils.cleanDirectory;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Optional;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;

import io.github.bonigarcia.wdm.WebDriverManager;
import io.github.bonigarcia.wdm.cache.CacheFilter;
import io.github.bonigarcia.wdm.etc.Architecture;
import io.github.bonigarcia.wdm.etc.Config;
import io.github.bonigarcia.wdm.etc.DriverManagerType;

/**
 * Test for driver cache.
 *
 * @author Boni Garcia (boni.gg@gmail.com)
 * @since 1.4.5
 */
@RunWith(Parameterized.class)
public class CacheTest {

    @Parameter(0)
    public DriverManagerType driverManagerType;

    @Parameter(1)
    public String driverName;

    @Parameter(2)
    public String driverVersion;

    @Parameter(3)
    public Architecture arch;

    @Parameter(4)
    public String os;

    @Parameters(name = "{index}: {0} {1}")
    public static Collection<Object[]> data() {
        return asList(new Object[][] {
                { CHROME, "chromedriver", "81.0.4044.69", DEFAULT, "linux" },
                { FIREFOX, "geckodriver", "0.26.0", DEFAULT, "linux" } });
    }

    @Before
    @After
    public void cleanCache() throws IOException {
        String cachePath = new Config().getCachePath();
        cleanDirectory(new File(cachePath));
    }

    @Test
    public void testCache() throws Exception {
        WebDriverManager browserManager = WebDriverManager
                .getInstance(driverManagerType);
        browserManager.forceDownload().driverVersion(driverVersion).setup();

        CacheFilter cacheFilter = new CacheFilter(new Config());
        Optional<String> driverFromCache = cacheFilter.getDriverFromCache(
                driverVersion, driverName, driverManagerType, arch, os);
        assertThat(driverFromCache.get(), notNullValue());
    }

}

@@ -895,16 +895,137 @@
 REFOX;%0D%0A
+import static io.github.bonigarcia.wdm.etc.OperatingSystem.LINUX;%0D%0Aimport static java.lang.invoke.MethodHandles.lookup;%0D%0A
 import s
@@ -1217,16 +1217,66 @@
 rtThat;%0D
+%0Aimport static org.slf4j.LoggerFactory.getLogger;%0D
 %0A%0D%0Aimpor
@@ -1633,16 +1633,42 @@
 meters;%0D
+%0Aimport org.slf4j.Logger;%0D
 %0A%0D%0Aimpor
@@ -1916,16 +1916,70 @@
 erType;%0D
+%0Aimport io.github.bonigarcia.wdm.etc.OperatingSystem;%0D
 %0A%0D%0A/**%0D%0A
@@ -2130,24 +2130,92 @@
 heTest %7B%0D%0A%0D%0A
+    static final Logger log = getLogger(lookup().lookupClass());%0D%0A%0D%0A
     @Paramet
@@ -2461,22 +2461,31 @@
  public 
-String
+OperatingSystem
  os;%0D%0A%0D%0A
@@ -2684,23 +2684,21 @@
 EFAULT, 
-%22linux%22
+LINUX
  %7D,%0D%0A   
@@ -2759,15 +2759,13 @@
 LT, 
-%22linux%22
+LINUX
  %7D %7D
@@ -2865,27 +2865,32 @@
     
-String cachePath = 
+cleanDirectory(new File(
 new 
@@ -2916,52 +2916,8 @@
 th()
-;%0D%0A        cleanDirectory(new File(cachePath
 ));%0D
@@ -3133,16 +3133,54 @@
 wnload()
+.operatingSystem(os)%0D%0A                
 .driverV
@@ -3425,16 +3425,87 @@
 arch, os
+.name());%0D%0A%0D%0A        log.debug(%22Driver from cache: %7B%7D%22, driverFromCache
 );%0D%0A    

Make cache test cross-platform