Back to project page AndroidPlaces.
The source code is released under:
Apache License
If you think the Android project AndroidPlaces listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Copyright (C) 2014 Brian Lee//from ww w . ja v a2 s .co m * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.tigerpenguin.places.request; import com.tigerpenguin.places.model.PlaceType; import com.tigerpenguin.places.model.RankBy; import com.tigerpenguin.places.response.NearbySearchResponse; import com.tigerpenguin.places.responsehandler.PlacesResponseHandler; public class NearbySearchRequestTest extends RequestTest { private final double latitude = 41.97957; private final double longitude = -87.62372; private final int radius = 1000; public void testNextPageSearch() throws Exception { final String pageToken = "foopage"; NearbySearchRequest nearbySearchRequest = new NearbySearchRequest( getContext(), pageToken, new TestResponseHandler()); String url = nearbySearchRequest.createUrl(); url = checkAndRemoveBaseParams(getContext(), url, PATH_NEARBY); url = checkAndRemoveParam(url, PARAM_PAGE_TOKEN, pageToken); checkUrlEmpty(url); checkValidation(nearbySearchRequest); } public void testLocationSearch() throws Exception { NearbySearchRequest nearbySearchRequest = new NearbySearchRequest( getContext(), new TestResponseHandler(), latitude, longitude, radius); String url = nearbySearchRequest.createUrl(); url = checkAndRemoveBaseParams(getContext(), url, PATH_NEARBY); url = checkAndRemoveLocation(url, latitude, longitude); url = checkAndRemoveParam(url, PARAM_RADIUS, radius); checkUrlEmpty(url); checkValidation(nearbySearchRequest); } public void testInvalidLocationSearch() throws Exception { final double invalidNegativeLatitude = -90.1; final double invalidPositiveLatitude = 90.1; final double invalidNegativeLongitude = -180.1; final double invalidPositiveLongitude = 180.1; final int invalidNegativeRadius = -1; final int invalidPositiveRadius = 50001; NearbySearchRequest nearbySearchRequest = null; // invalid negative latitude try { nearbySearchRequest = new NearbySearchRequest( getContext(), new TestResponseHandler(), invalidNegativeLatitude, longitude, radius); } catch (IllegalArgumentException iae) { // expected } assertNull("Invalid negative latitude was accepted", nearbySearchRequest); // invalid positive latitude try { nearbySearchRequest = new NearbySearchRequest( getContext(), new TestResponseHandler(), invalidPositiveLatitude, longitude, radius); } catch (IllegalArgumentException iae) { // expected } assertNull("Invalid positive latitude was accepted", nearbySearchRequest); // invalid negative longitude try { nearbySearchRequest = new NearbySearchRequest( getContext(), new TestResponseHandler(), latitude, invalidNegativeLongitude, radius); } catch (IllegalArgumentException iae) { // expected } assertNull("Invalid negative longitude was accepted", nearbySearchRequest); // invalid positive longitude try { nearbySearchRequest = new NearbySearchRequest( getContext(), new TestResponseHandler(), latitude, invalidPositiveLongitude, radius); } catch (IllegalArgumentException iae) { // expected } assertNull("Invalid positive longitude was accepted", nearbySearchRequest); // invalid negative radius try { nearbySearchRequest = new NearbySearchRequest( getContext(), new TestResponseHandler(), latitude, longitude, invalidNegativeRadius); } catch (IllegalArgumentException iae) { // expected } assertNull("Invalid negative radius was accepted", nearbySearchRequest); // invalid positive radius try { nearbySearchRequest = new NearbySearchRequest( getContext(), new TestResponseHandler(), latitude, longitude, invalidPositiveRadius); } catch (IllegalArgumentException iae) { // expected } assertNull("Invalid positive radius was accepted", nearbySearchRequest); } public void testKeywordSearch() throws Exception { final String keyword = "Android"; NearbySearchRequest nearbySearchRequest = new NearbySearchRequest( getContext(), new TestResponseHandler(), latitude, longitude, keyword, null); String url = nearbySearchRequest.createUrl(); url = checkAndRemoveBaseParams(getContext(), url, PATH_NEARBY); url = checkAndRemoveLocation(url, latitude, longitude); url = checkAndRemoveParam(url, PARAM_KEYWORD, keyword); url = checkAndRemoveParam(url, PARAM_RANK_BY, RankBy.DISTANCE); checkUrlEmpty(url); checkValidation(nearbySearchRequest); } public void testNameSearch() throws Exception { final String name = "KitKat"; NearbySearchRequest nearbySearchRequest = new NearbySearchRequest( getContext(), new TestResponseHandler(), latitude, longitude, null, name); String url = nearbySearchRequest.createUrl(); url = checkAndRemoveBaseParams(getContext(), url, PATH_NEARBY); url = checkAndRemoveLocation(url, latitude, longitude); url = checkAndRemoveParam(url, PARAM_NAME, name); url = checkAndRemoveParam(url, PARAM_RANK_BY, RankBy.DISTANCE); checkUrlEmpty(url); checkValidation(nearbySearchRequest); } public void testPlaceTypeSearch() throws Exception { final PlaceType placeType = PlaceType.AMUSEMENT_PARK; NearbySearchRequest nearbySearchRequest = new NearbySearchRequest( getContext(), new TestResponseHandler(), latitude, longitude, null, null, placeType); String url = nearbySearchRequest.createUrl(); url = checkAndRemoveBaseParams(getContext(), url, PATH_NEARBY); url = checkAndRemoveLocation(url, latitude, longitude); url = checkAndRemovePlaceTypes(url, placeType); url = checkAndRemoveParam(url, PARAM_RANK_BY, RankBy.DISTANCE); checkUrlEmpty(url); checkValidation(nearbySearchRequest); } public void testInvalidDistanceSearch() throws Exception { NearbySearchRequest nearbySearchRequest = null; try { nearbySearchRequest = new NearbySearchRequest( getContext(), new TestResponseHandler(), latitude, longitude, null, null); } catch (IllegalArgumentException iae) { // expected } assertNull("Invalid distance search was accepted", nearbySearchRequest); } public void testValidateLocation() throws Exception { NearbySearchRequest nearbySearchRequest = new NearbySearchRequest( getContext(), new TestResponseHandler(), latitude, longitude, radius); nearbySearchRequest.removeParameter(PARAM_LOCATION); checkExecutionValidated(nearbySearchRequest); } public void testValidateRadius() throws Exception { NearbySearchRequest nearbySearchRequest =new NearbySearchRequest( getContext(), new TestResponseHandler(), latitude, longitude, radius); nearbySearchRequest.removeParameter(PARAM_RADIUS); checkExecutionValidated(nearbySearchRequest); } public void testValidateKeyword() throws Exception { final String keyword = "Android"; NearbySearchRequest nearbySearchRequest = new NearbySearchRequest( getContext(), new TestResponseHandler(), latitude, longitude, keyword, null); nearbySearchRequest.setKeyword(null); checkExecutionValidated(nearbySearchRequest); } public void testValidateName() throws Exception { final String name = "KitKat"; NearbySearchRequest nearbySearchRequest = new NearbySearchRequest( getContext(), new TestResponseHandler(), latitude, longitude, null, name); nearbySearchRequest.setName(null); checkExecutionValidated(nearbySearchRequest); } public void testValidatePlaceType() throws Exception { NearbySearchRequest nearbySearchRequest = new NearbySearchRequest( getContext(), new TestResponseHandler(), latitude, longitude, null, null, PlaceType.BAR); nearbySearchRequest.setTypes(null); checkExecutionValidated(nearbySearchRequest); } private static class TestResponseHandler implements PlacesResponseHandler<NearbySearchResponse> { @Override public void handleResponse(NearbySearchResponse nearbySearchResponse) { } } }