@Test(expected = WrongPageError.class)
  public void the_pages_object_throws_a_wrong_page_error_when_the_page_object_is_invalid() {

    when(driver.getCurrentUrl()).thenReturn("http://www.google.com");
    final Pages pages = new Pages(driver, configuration);
    pages.start();

    pages.currentPageAt(InvalidHomePage.class);
  }
  @Test
  public void the_pages_object_knows_when_we_are_not_on_the_right_page() {

    when(driver.getCurrentUrl()).thenReturn("http://www.google.org");
    final Pages pages = new Pages(driver, configuration);
    pages.start();

    assertThat(pages.isCurrentPageAt(ApacheHomePage.class), is(false));
  }
  @Test
  public void should_be_able_to_retrieve_the_current_page_as_an_instance_of_AnyPage() {

    when(driver.getCurrentUrl()).thenReturn("http://www.apache.org");
    final Pages pages = new Pages(driver, configuration);
    pages.start();

    AnyPage currentPage = pages.getAt(AnyPage.class);
    assertThat(currentPage, is(not(nullValue())));
  }
  @Test
  public void the_getAt_method_is_Groovy_shorthand_for_currentPageAt() {

    when(driver.getCurrentUrl()).thenReturn("http://www.apache.org");
    final Pages pages = new Pages(driver, configuration);
    pages.start();

    assertThat(
        pages.getAt(ApacheHomePage.class).getClass().getName(), is(ApacheHomePage.class.getName()));
  }
  @Test
  public void the_pages_object_should_have_a_default_starting_point_url() {

    final String baseUrl = "http://www.google.com";
    final Pages pages = new Pages(driver, configuration);

    pages.setDefaultBaseUrl(baseUrl);

    pages.start();

    verify(driver).get(baseUrl);
  }
  @Test
  public void the_default_starting_point_url_can_be_overriden_by_a_system_property() {

    final String systemDefinedBaseUrl = "http://www.google.com.au";

    Configuration Configuration = new SystemPropertiesConfiguration(environmentVariables);
    final Pages pages = new Pages(driver, Configuration);

    environmentVariables.setProperty("webdriver.base.url", systemDefinedBaseUrl);

    pages.start();

    verify(driver).get(systemDefinedBaseUrl);
  }
  @Test
  public void the_default_starting_point_url_can_refer_to_a_file_on_the_classpath() {

    final String baseUrl = "classpath:static-site/index.html";
    final Pages pages = new Pages(driver, configuration);
    pages.setDefaultBaseUrl(baseUrl);

    URL staticSiteUrl =
        Thread.currentThread().getContextClassLoader().getResource("static-site/index.html");

    pages.start();

    verify(driver).get(staticSiteUrl.toString());
  }