package me.alb_i986.selenium.tinafw.domain;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class BrowserTest {

	private Browser browser;

	@Before
	public void before() {
		this.browser = new Browser();
	}
	
	
	/**
	 * Testing post conditions of {@link Browser#open()}:
	 * <ol>
	 * <li>Given a Browser with a null WebDriver</li>
	 * <li>When I open the browser</li>
	 * <li>Then {@link Browser#isOpen()} should return true</li>
	 * <li>And {@link Browser#getWebDriver()} should be not null</li>
	 * </ol>
	 */
	@Test
	public void givenNullDriverWhenOpenThenBrowserShouldBeOpen() {
		browser.setDriver(null);
		browser.open();
		assertTrue(browser.isOpen());
		assertNotNull(browser.getWebDriver());
	}

	/**
	 * Testing post conditions of {@link Browser#Browser()}:
	 * <ol>
	 * <li>When I instantiate Browser</li>
	 * <li>Then {@link Browser#getWebDriver()} should be null</li>
	 * <li>And {@link Browser#isOpen()} should return false</li>
	 * </ol>
	 */
	@Test
	public void whenNewBrowserThenDriverShouldBeNull() {
		browser = new Browser();
		assertNull(browser.getWebDriver());
		assertFalse(browser.isOpen());
	}

	
	/**
	 * Testing post conditions of {@link Browser#close()}:
	 * <ol>
	 * <li>Given a fresh new instance of Browser</li>
	 * <li>When I close the browser</li>
	 * <li>Then {@link Browser#isOpen()} should return false</li>
	 * <li>And {@link Browser#getWebDriver()} should return null</li>
	 * </ol>
	 */
	@Test
	public void givenNullDriverWhenCloseThenBrowserShouldBeClosed() {
		browser.setDriver(null);
		browser.close();
		assertFalse(browser.isOpen());
		assertNull(browser.getWebDriver());
	}

	/**
	 * Testing post conditions of {@link Browser#close()}:
	 * <ol>
	 * <li>Given a Browser with an initial not null WebDriver</li>
	 * <li>When I close the browser</li>
	 * <li>Then {@link Browser#isOpen()} should return false</li>
	 * <li>And {@link Browser#getWebDriver()} should return null</li>
	 * </ol>
	 */
	@Test
	public void givenNotNullDriverWhenCloseThenBrowserShouldBeClosed() {
		browser.setDriver(new HtmlUnitDriver());
		browser.close();
		assertFalse(browser.isOpen());
		assertNull(browser.getWebDriver());
	}


	/**
	 * Trusts (?!) {@link Browser#getWebDriver()} to return the
	 * correct underlying WebDriver, in order to tear down
	 * the test by quitting the driver.
	 */
	@After
	public void after() {
		WebDriver driver = this.browser.getWebDriver();
		if(driver!=null)
			driver.quit();
	}
	
}

@@ -503,27 +503,22 @@
  I open 
-the browser
+Chrome
 %3C/li%3E%0A%09 
@@ -547,103 +547,103 @@
 ser#
-isOpen()%7D should return true%3C/li%3E%0A%09 * %3Cli%3EAnd %7B@link Browser#getWebDriver()%7D should be not null
+getWebDriver()%7D should be not null%3C/li%3E%0A%09 * %3Cli%3EAnd %7B@link Browser#isOpen()%7D should return true
 %3C/li
@@ -706,31 +706,33 @@
 Open
-ThenBrowserShouldBeOpen
+ChromeThenDriverIsNotNull
 () %7B
@@ -778,40 +778,31 @@
 pen(
-);%0A%09%09assertTrue(browser.isOpen()
+SupportedBrowser.CHROME
 );%0A%09
@@ -833,32 +833,64 @@
 etWebDriver());%0A
+%09%09assertTrue(browser.isOpen());%0A
 %09%7D%0A%0A%09/**%0A%09 * Tes

fix BrowserTest after changing Browser