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/* w w w .j a va2 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 android.content.Context; import com.tigerpenguin.places.response.PlacesResponse; import com.tigerpenguin.places.response.PlacesResponseFactory; import com.tigerpenguin.places.responsehandler.PlacesResponseHandler; public class PlacesRequestTest extends RequestTest { public void testBasicUrl() throws Exception { TestPlacesRequest testPlacesRequest = new TestPlacesRequest(getContext()); String url = testPlacesRequest.createUrl(); url = checkAndRemoveBaseParams(getContext(), url, null); checkUrlEmpty(url); checkValidation(testPlacesRequest); } public void testSuperValidateCalled() throws Exception { RudePlacesRequest rudePlacesRequest = new RudePlacesRequest(getContext()); boolean exceptionCaught = false; try { rudePlacesRequest.execute(); } catch (IllegalStateException ise) { exceptionCaught = true; } assertTrue("PlacesRequest executed without calling through super.validate()", exceptionCaught); } public void testSetParameter() throws Exception { final String parameter = "foo"; final String value = "bar"; TestPlacesRequest testPlacesRequest = new TestPlacesRequest(getContext()); testPlacesRequest.setParameter(parameter, value); // checkParameterDefined try { testPlacesRequest.checkParameterDefined(parameter, ""); } catch (InvalidRequestException ire) { fail("Unable to find parameter that was set"); } // getParameter assertEquals(value, testPlacesRequest.getParameter(parameter)); // unset testPlacesRequest.setParameter(parameter, null); boolean exceptionCaught = false; try { testPlacesRequest.checkParameterDefined(parameter, ""); } catch (InvalidRequestException ire) { exceptionCaught = true; } assertTrue("Parameter wasn't unset", exceptionCaught); assertNull("Parameter wasn't unset", testPlacesRequest.getParameter(parameter)); } public void testRemoveParameter() throws Exception { final String parameter = "foo"; final String value = "bar"; TestPlacesRequest testPlacesRequest = new TestPlacesRequest(getContext()); testPlacesRequest.setParameter(parameter, value); // checkParameterDefined try { testPlacesRequest.checkParameterDefined(parameter, ""); } catch (InvalidRequestException ire) { fail("Unable to find parameter that was set"); } testPlacesRequest.removeParameter(parameter); boolean exceptionCaught = false; try { testPlacesRequest.checkParameterDefined(parameter, ""); } catch (InvalidRequestException ire) { exceptionCaught = true; } assertTrue("Parameter wasn't unset", exceptionCaught); assertNull("Parameter wasn't unset", testPlacesRequest.getParameter(parameter)); } private static class TestPlacesRequest extends PlacesRequest<PlacesRequest, PlacesResponse> { private TestPlacesRequest(Context context) { super(context, new TestResponseHandler()); } @Override protected PlacesResponseFactory<PlacesRequest, PlacesResponse> getResponseFactory() { return null; } @Override protected PlacesRequest getThis() { return null; } @Override protected String getRequestPath() { return ""; } } private static class RudePlacesRequest extends TestPlacesRequest { private RudePlacesRequest(Context context) { super(context); } @Override protected void validate() throws InvalidRequestException { // don't call super() } } private static class TestResponseHandler implements PlacesResponseHandler<PlacesResponse> { @Override public void handleResponse(PlacesResponse response) { } } }