Package geodress.tests

Source Code of geodress.tests.GoogleMapsReaderTest

/**
* GeoDress - A program for reverse geocoding
* Copyright (C) 2010  Stefan T.
*
* See COPYING for Details.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package geodress.tests;

import geodress.model.Coordinate;
import geodress.model.reader.GoogleMapsReader;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
* Tests the {@link GoogleMapsReader} class (needs Internet connection).
*
* @author Stefan T.
*/
public class GoogleMapsReaderTest {

  /** test reader */
  private GoogleMapsReader testReader;
  /** test coordinate */
  private Coordinate testCoordinate1;
  /** test coordinate */
  private Coordinate testCoordinate2;
  /** test coordinate */
  private Coordinate testCoordinate3;
  /**
   * time in milliseconds to wait between 2 Google Maps requests @see
   * PictureBox#requestInterval
   */
  private final long REQUEST_INTERVAL = 200;

  /**
   * Initializes the objects.
   *
   * @throws java.lang.Exception
   */
  @Before
  public void setUp() throws Exception {
    /* Berliner Straße 1, 13507 Berlin, Germany */
    testCoordinate1 = new Coordinate(52.589840, 13.283194);
    /* Place Charles-de-Gaulle, 75008 Paris, France */
    testCoordinate2 = new Coordinate(48.873901, 2.295899);
    /*
     * Cmte. Luis Piedrabuena 600-699, Río Grande, Tierra del Fuego,
     * Argentina
     */
    testCoordinate3 = new Coordinate(-53.784956, -67.703286);

    testReader = new GoogleMapsReader();
  }

  /**
   * Makes a test for getting the address of a coordinate.
   *
   * @throws Exception
   *             may cause an exception
   */
  @Test
  public void testGetAddress1() throws Exception {
    String testedAddress = testReader.getAddress(testCoordinate1)
        .toString();
    String[] expectedAddress = new String[] { "Berliner Straße", "13507",
        "Berlin", "Germany" };

    for (String addressPart : expectedAddress) {
      Assert.assertTrue("test demand '" + testedAddress
          + "' does not contain '" + addressPart + "'", testedAddress
          .contains(addressPart));
    }
  }

  /**
   * Makes a test for getting the address of a coordinate.
   *
   * @throws Exception
   *             may cause an exception
   */
  @Test
  public void testGetAddress2() throws Exception {
    String testedAddress = testReader.getAddress(testCoordinate2)
        .toString();
    String[] expectedAddress = new String[] { "Place", "Charles", "de",
        "Gaulle", "75008", "Paris", "France" };

    for (String addressPart : expectedAddress) {
      Assert.assertTrue("test demand '" + testedAddress
          + "' does not contain '" + addressPart + "'", testedAddress
          .contains(addressPart));
    }
  }

  /**
   * Calls {@link GoogleMapsReaderTest#testGetAddress1()} very often in short
   * time.
   *
   * @throws Exception
   *             may cause an exception
   */
  @Test
  public void testGetAddressOften1() throws Exception {
    for (int i = 0; i < 10; i++) {
      testGetAddress1();
      Thread.sleep(REQUEST_INTERVAL);
    }
  }

  /**
   * Makes a test for getting the address of a coordinate very often in short
   * time.
   *
   * @throws Exception
   *             may cause an exception
   */
  @Test
  public void testGetAddressOften2() throws Exception {
    String[] expectedAddress = new String[] { "Luis Piedrabuena", "600",
        "rande", "Tierra", "del", "Fuego", "Argentina" };

    for (int i = 0; i < 10; i++) {
      String testedAddress = testReader.getAddress(testCoordinate3)
          .toString();
      for (String addressPart : expectedAddress) {
        Assert.assertTrue("test demand '" + testedAddress
            + "' does not contain '" + addressPart
            + "' (repetition " + i + ")", testedAddress
            .contains(addressPart));
      }
      Thread.sleep(REQUEST_INTERVAL);
    }
  }
}
TOP

Related Classes of geodress.tests.GoogleMapsReaderTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.