コード例 #1
0
  @Test
  public void shouldConnectCorrectly() {
    PlacesResult result;

    // Test access denied response
    places.setApiKey("WRONG_API_KEY");
    result =
        places.search(
            PICCADILLY_LAT,
            PICCADILLY_LONG,
            RADIUS,
            PlacesQueryOptions.create().types(PLACE_TYPES),
            false);

    assertEquals("REQUEST_DENIED", result.getStatus());
    assertEquals(false, result.isOkay());

    // Test success connection
    places.setApiKey(API_KEY);
    result =
        places.search(
            PICCADILLY_LAT,
            PICCADILLY_LONG,
            RADIUS,
            PlacesQueryOptions.create().types(PLACE_TYPES),
            false);

    assertEquals("OK", result.getStatus());
    assertEquals(true, result.isOkay());
  }
コード例 #2
0
  @Test
  public void shouldSearchNearbyPlacesCorrectly() {
    GooglePlaces places = new GooglePlaces(API_KEY);
    boolean searchResultIsEmpty = true;

    // Search places nearby
    PlacesResult result =
        places.search(
            PICCADILLY_LAT,
            PICCADILLY_LONG,
            RADIUS,
            PlacesQueryOptions.create().types(PLACE_TYPES),
            false);
    assertEquals(true, result.isOkay());

    // Foreach all result places and compare results to detail responses by separated Google Places
    // API call
    for (Place place : result) {
      String reference = place.getReference();
      String id = place.getId();
      String name = place.getName();
      float latitude = place.getGeometry().getLocation().getLatitude();
      float longitude = place.getGeometry().getLocation().getLongitude();

      // Send Google Places Detail request
      PlaceDetailResult detailResult = places.detail(reference, false);
      assertEquals(true, detailResult.isOkay());

      // Compare detail request result to the previously received Nearby search request
      assertEquals(id, detailResult.getResult().getId());
      assertEquals(name, detailResult.getResult().getName());
      assertEquals(latitude, detailResult.getResult().getGeometry().getLocation().getLatitude());
      assertEquals(longitude, detailResult.getResult().getGeometry().getLocation().getLongitude());

      // Set result is not empty flag to false
      searchResultIsEmpty = false;
    }

    // There always must be something near Piccadilly Circus
    assertEquals(false, searchResultIsEmpty);
  }