/*
 * (C) Copyright 2016 Boni Garcia (http://bonigarcia.github.io/)
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * This library 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.
 *
 */
package io.github.bonigarcia.wdm.test;

import static io.github.bonigarcia.wdm.Architecture.x32;
import static io.github.bonigarcia.wdm.Architecture.x64;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;

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.Architecture;
import io.github.bonigarcia.wdm.BrowserManager;
import io.github.bonigarcia.wdm.ChromeDriverManager;
import io.github.bonigarcia.wdm.Downloader;
import io.github.bonigarcia.wdm.FirefoxDriverManager;
import io.github.bonigarcia.wdm.OperaDriverManager;
import io.github.bonigarcia.wdm.PhantomJsDriverManager;

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

	@Parameter(0)
	public Class<? extends BrowserManager> browserManagerClass;

	@Parameter(1)
	public String driverVersion;

	@Parameter(2)
	public Architecture architecture;

	@Parameters(name = "{index}: {0} {1} {2}")
	public static Collection<Object[]> data() {
		return Arrays.asList(
				new Object[][] { { ChromeDriverManager.class, "2.23", x32 },
						{ OperaDriverManager.class, "0.2.2", x64 },
						{ PhantomJsDriverManager.class, "2.1.1", x64 },
						{ FirefoxDriverManager.class, "0.10.0", x64 } });
	}

	@Test
	public void testCache() throws Exception {
		BrowserManager browserManager = null;
		if (browserManagerClass.equals(ChromeDriverManager.class)) {
			browserManager = ChromeDriverManager.getInstance();
		} else if (browserManagerClass.equals(OperaDriverManager.class)) {
			browserManager = OperaDriverManager.getInstance();
		} else if (browserManagerClass.equals(PhantomJsDriverManager.class)) {
			browserManager = PhantomJsDriverManager.getInstance();
		} else if (browserManagerClass.equals(FirefoxDriverManager.class)) {
			browserManager = FirefoxDriverManager.getInstance();
		}

		browserManager.architecture(architecture).version(driverVersion)
				.setup();
		Downloader downloader = new Downloader(browserManager);

		Method method = BrowserManager.class.getDeclaredMethod(
				"existsDriverInCache", String.class, String.class,
				Architecture.class);
		method.setAccessible(true);
		String driverInChachePath = (String) method.invoke(browserManager,
				downloader.getTargetPath(), driverVersion, architecture);

		assertThat(driverInChachePath, notNullValue());
	}

}

@@ -1138,155 +1138,244 @@
 rs;%0A
-%0A
 import 
-io.github.bonigarcia.wdm.Architecture;%0Aimport io.github.bonigarcia.wdm.BrowserManager;%0Aimport io.github.bonigarcia.wdm.ChromeDriverManager;
+org.openqa.selenium.WebDriver;%0Aimport org.openqa.selenium.chrome.ChromeDriver;%0Aimport org.openqa.selenium.firefox.FirefoxDriver;%0Aimport org.openqa.selenium.opera.OperaDriver;%0Aimport org.openqa.selenium.phantomjs.PhantomJSDriver;%0A
 %0Aimp
@@ -1403,26 +1403,28 @@
 cia.wdm.
-Downloader
+Architecture
 ;%0Aimport
@@ -1449,27 +1449,21 @@
 cia.wdm.
-FirefoxDriv
+Brows
 erManage
@@ -1497,32 +1497,24 @@
 cia.wdm.
-OperaDriverManag
+Download
 er;%0Aimpo
@@ -1541,25 +1541,19 @@
 cia.wdm.
-PhantomJs
+Web
 DriverMa
@@ -1755,36 +1755,23 @@
 nds 
-BrowserManager%3E browserManag
+WebDriver%3E driv
 erCl
@@ -1981,16 +1981,21 @@
 rays
+%0A%09%09%09%09
 .asList(
 %0A%09%09%09
@@ -1990,21 +1990,16 @@
 .asList(
-%0A%09%09%09%09
 new Obje
@@ -2017,31 +2017,24 @@
 ChromeDriver
-Manager
 .class, %222.2
@@ -2033,17 +2033,17 @@
 ss, %222.2
-3
+7
 %22, x32 %7D
@@ -2059,31 +2059,24 @@
  OperaDriver
-Manager
 .class, %220.2
@@ -2099,38 +2099,31 @@
 %09%09%7B PhantomJ
-s
+S
 Driver
-Manager
 .class, %222.1
@@ -2151,31 +2151,24 @@
 irefoxDriver
-Manager
 .class, %220.1
@@ -2167,17 +2167,17 @@
 ss, %220.1
-0
+4
 .0%22, x64
@@ -2276,517 +2276,55 @@
 r = 
-null;%0A%09%09if (browserManagerClass.equals(ChromeDriverManager.class)) %7B%0A%09%09%09browserManager = ChromeDriverManager.getInstance();%0A%09%09%7D else if (browserManagerClass.equals(OperaDriverManager.class)) %7B%0A%09%09%09browserManager = OperaDriverManager.getInstance();%0A%09%09%7D else if (browserManagerClass.equals(PhantomJsDriverManager.class)) %7B%0A%09%09%09browserManager = PhantomJsDriverManager.getInstance();%0A%09%09%7D else if (browserManagerClass.equals(FirefoxDriverManager.class)) %7B%0A%09%09%09browserManager = FirefoxDriverManager.getInstance();%0A%09%09%7D%0A
+WebDriverManager%0A%09%09%09%09.getInstance(driverClass);
 %0A%09%09b

Use generic manager (WebDriverManager) in CacheTest