Android Open Source - Android_Sunshine_Udacity Test Uri Matcher






From Project

Back to project page Android_Sunshine_Udacity.

License

The source code is released under:

MIT License

If you think the Android project Android_Sunshine_Udacity listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2014 The Android Open Source Project
 *//ww w  . j  av  a2  s . c o 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.example.talonso.sunshine.data;

        import android.content.UriMatcher;
        import android.net.Uri;
        import android.test.AndroidTestCase;

/*
    Uncomment this class when you are ready to test your UriMatcher.  Note that this class utilizes
    constants that are declared with package protection inside of the UriMatcher, which is why
    the test must be in the same data package as the Android app code.  Doing the test this way is
    a nice compromise between data hiding and testability.
 */
public class TestUriMatcher extends AndroidTestCase {
    private static final String LOCATION_QUERY = "London, UK";
    private static final long TEST_DATE = 1419033600L;  // December 20th, 2014
    private static final long TEST_LOCATION_ID = 10L;

    // content://com.example.android.sunshine.app/weather"
    private static final Uri TEST_WEATHER_DIR = WeatherContract.WeatherEntry.CONTENT_URI;
    private static final Uri TEST_WEATHER_WITH_LOCATION_DIR = WeatherContract.WeatherEntry.buildWeatherLocation(LOCATION_QUERY);
    private static final Uri TEST_WEATHER_WITH_LOCATION_AND_DATE_DIR = WeatherContract.WeatherEntry.buildWeatherLocationWithDate(LOCATION_QUERY, TEST_DATE);
    // content://com.example.android.sunshine.app/location"
    private static final Uri TEST_LOCATION_DIR = WeatherContract.LocationEntry.CONTENT_URI;

    /*
        Students: This function tests that your UriMatcher returns the correct integer value
        for each of the Uri types that our ContentProvider can handle.  Uncomment this when you are
        ready to test your UriMatcher.
     */
    public void testUriMatcher() {
        UriMatcher testMatcher = WeatherProvider.buildUriMatcher();

        assertEquals("Error: The WEATHER URI was matched incorrectly.",
                testMatcher.match(TEST_WEATHER_DIR), WeatherProvider.WEATHER);
        assertEquals("Error: The WEATHER WITH LOCATION URI was matched incorrectly.",
                testMatcher.match(TEST_WEATHER_WITH_LOCATION_DIR), WeatherProvider.WEATHER_WITH_LOCATION);
        assertEquals("Error: The WEATHER WITH LOCATION AND DATE URI was matched incorrectly.",
                testMatcher.match(TEST_WEATHER_WITH_LOCATION_AND_DATE_DIR), WeatherProvider.WEATHER_WITH_LOCATION_AND_DATE);
        assertEquals("Error: The LOCATION URI was matched incorrectly.",
                testMatcher.match(TEST_LOCATION_DIR), WeatherProvider.LOCATION);
    }
}




Java Source Code List

com.example.talonso.sunshine.DetailActivity.java
com.example.talonso.sunshine.DetailFragment.java
com.example.talonso.sunshine.ForecastAdapter.java
com.example.talonso.sunshine.ForecastFragment.java
com.example.talonso.sunshine.FullTestSuite.java
com.example.talonso.sunshine.MainActivity.java
com.example.talonso.sunshine.SettingsActivity.java
com.example.talonso.sunshine.Utility.java
com.example.talonso.sunshine.data.TestDb.java
com.example.talonso.sunshine.data.TestProvider.java
com.example.talonso.sunshine.data.TestUriMatcher.java
com.example.talonso.sunshine.data.TestUtilities.java
com.example.talonso.sunshine.data.TestWeatherContract.java
com.example.talonso.sunshine.data.WeatherContract.java
com.example.talonso.sunshine.data.WeatherDbHelper.java
com.example.talonso.sunshine.data.WeatherProvider.java
com.example.talonso.sunshine.sync.SunshineAuthenticatorService.java
com.example.talonso.sunshine.sync.SunshineAuthenticator.java
com.example.talonso.sunshine.sync.SunshineSyncAdapter.java
com.example.talonso.sunshine.utils.PollingCheck.java