Java Code Examples for android.content.pm.PackageManager.getProviderInfo()

The following are Jave code examples for showing how to use getProviderInfo() of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: MovieGuide   File: TestProvider.java   View Source Code Vote up 7 votes
@Test
public void testProviderRegistry() {
    Context appContext = InstrumentationRegistry.getTargetContext();
    PackageManager pm = appContext.getPackageManager();

    // We define the component name based on the package name from the context and the
    // Provider class.
    ComponentName componentName = new ComponentName(appContext.getPackageName(),
            FavoritesProvider.class.getName());
    try {
        // Fetch the provider info using the component name from the PackageManager
        // This throws an exception if the provider isn't registered.
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);

        // Make sure that the registered authority matches the authority from the Contract.
        assertEquals("Error: FavoritesProvider registered with authority: " + providerInfo.authority
                + " instead of authority: " + FavoritesContract.AUTHORITY,
                providerInfo.authority, FavoritesContract.AUTHORITY);
    } catch (PackageManager.NameNotFoundException e) {
        // I guess the provider isn't registered correctly.
        assertTrue("Error: FavoritesProvider not registered at " + appContext.getPackageName(),
                false);
    }
}
 
Example 2
Project: CodeWatch   File: TestProvider.java   View Source Code Vote up 6 votes
public void testProviderRegistry() {
    PackageManager pm = mContext.getPackageManager();

    ComponentName componentName = new ComponentName(mContext.getPackageName(),
            LeaderProvider.class.getName());
    try {
        // Fetch the provider info using the component name from the PackageManager
        // This throws an exception if the provider isn't registered.
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);

        // Make sure that the registered authority matches the authority from the Contract.
        assertEquals("Error: LeaderProvider registered with authority: " + providerInfo.authority +
                " instead of authority: " + LeaderContract.CONTENT_AUTHORITY,
                providerInfo.authority, LeaderContract.CONTENT_AUTHORITY);
    } catch (PackageManager.NameNotFoundException e) {
        assertTrue("Error: LeaderProvider not registered at " + mContext.getPackageName(),
                false);
    }
}
 
Example 3
Project: ubiquitous   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) Your WeatherProvider was registered with the incorrect authority
 * <p>
 *   2) Your WeatherProvider was not registered at all
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String weatherProviderClassName = WeatherProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, weatherProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = WeatherContract.CONTENT_AUTHORITY;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: WeatherProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: WeatherProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
Example 4
Project: Android_Sunshine_Watch   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) Your WeatherProvider was registered with the incorrect authority
 * <p>
 *   2) Your WeatherProvider was not registered at all
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String weatherProviderClassName = WeatherProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, weatherProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = WeatherContract.CONTENT_AUTHORITY;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: WeatherProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: WeatherProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
Example 5
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) Your WeatherProvider was registered with the incorrect authority
 * <p>
 *   2) Your WeatherProvider was not registered at all
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String weatherProviderClassName = WeatherProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, weatherProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = WeatherContract.CONTENT_AUTHORITY;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: WeatherProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: WeatherProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
Example 6
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) Your WeatherProvider was registered with the incorrect authority
 * <p>
 *   2) Your WeatherProvider was not registered at all
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String weatherProviderClassName = WeatherProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, weatherProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = WeatherContract.CONTENT_AUTHORITY;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: WeatherProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: WeatherProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
Example 7
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) Your WeatherProvider was registered with the incorrect authority
 * <p>
 *   2) Your WeatherProvider was not registered at all
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String weatherProviderClassName = WeatherProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, weatherProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = WeatherContract.CONTENT_AUTHORITY;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: WeatherProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: WeatherProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
Example 8
Project: android-dev-challenge   File: TestTaskContentProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String taskProviderClassName = TaskContentProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, taskProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = packageName;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: TaskContentProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: TaskContentProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
Example 9
Project: android-dev-challenge   File: TestTaskContentProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String taskProviderClassName = TaskContentProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, taskProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = packageName;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: TaskContentProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: TaskContentProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
Example 10
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) Your WeatherProvider was registered with the incorrect authority
 * <p>
 *   2) Your WeatherProvider was not registered at all
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String weatherProviderClassName = WeatherProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, weatherProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = WeatherContract.CONTENT_AUTHORITY;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: WeatherProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: WeatherProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
Example 11
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) Your WeatherProvider was registered with the incorrect authority
 * <p>
 *   2) Your WeatherProvider was not registered at all
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String weatherProviderClassName = WeatherProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, weatherProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = WeatherContract.CONTENT_AUTHORITY;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: WeatherProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: WeatherProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
Example 12
Project: GoUbiquitous   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) Your WeatherProvider was registered with the incorrect authority
 * <p>
 *   2) Your WeatherProvider was not registered at all
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String weatherProviderClassName = WeatherProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, weatherProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = WeatherContract.CONTENT_AUTHORITY;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: WeatherProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: WeatherProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
Example 13
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) Your WeatherProvider was registered with the incorrect authority
 * <p>
 *   2) Your WeatherProvider was not registered at all
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String weatherProviderClassName = WeatherProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, weatherProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = WeatherContract.CONTENT_AUTHORITY;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: WeatherProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: WeatherProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
Example 14
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) Your WeatherProvider was registered with the incorrect authority
 * <p>
 *   2) Your WeatherProvider was not registered at all
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String weatherProviderClassName = WeatherProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, weatherProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = WeatherContract.CONTENT_AUTHORITY;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: WeatherProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: WeatherProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
Example 15
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) Your WeatherProvider was registered with the incorrect authority
 * <p>
 *   2) Your WeatherProvider was not registered at all
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String weatherProviderClassName = WeatherProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, weatherProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = WeatherContract.CONTENT_AUTHORITY;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: WeatherProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: WeatherProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
Example 16
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) Your WeatherProvider was registered with the incorrect authority
 * <p>
 *   2) Your WeatherProvider was not registered at all
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String weatherProviderClassName = WeatherProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, weatherProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = WeatherContract.CONTENT_AUTHORITY;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: WeatherProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: WeatherProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
Example 17
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) Your WeatherProvider was registered with the incorrect authority
 * <p>
 *   2) Your WeatherProvider was not registered at all
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String weatherProviderClassName = WeatherProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, weatherProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = WeatherContract.CONTENT_AUTHORITY;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: WeatherProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: WeatherProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
Example 18
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) Your WeatherProvider was registered with the incorrect authority
 * <p>
 *   2) Your WeatherProvider was not registered at all
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String weatherProviderClassName = WeatherProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, weatherProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = WeatherContract.CONTENT_AUTHORITY;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: WeatherProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: WeatherProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
Example 19
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) Your WeatherProvider was registered with the incorrect authority
 * <p>
 *   2) Your WeatherProvider was not registered at all
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String weatherProviderClassName = WeatherProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, weatherProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = WeatherContract.CONTENT_AUTHORITY;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: WeatherProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: WeatherProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}
 
Example 20
Project: android-dev-challenge   File: TestWeatherProvider.java   View Source Code Vote up 4 votes
/**
 * This test checks to make sure that the content provider is registered correctly in the
 * AndroidManifest file. If it fails, you should check the AndroidManifest to see if you've
 * added a <provider/> tag and that you've properly specified the android:authorities attribute.
 * <p>
 * Potential causes for failure:
 * <p>
 *   1) Your WeatherProvider was registered with the incorrect authority
 * <p>
 *   2) Your WeatherProvider was not registered at all
 */
@Test
public void testProviderRegistry() {

    /*
     * A ComponentName is an identifier for a specific application component, such as an
     * Activity, ContentProvider, BroadcastReceiver, or a Service.
     *
     * Two pieces of information are required to identify a component: the package (a String)
     * it exists in, and the class (a String) name inside of that package.
     *
     * We will use the ComponentName for our ContentProvider class to ask the system
     * information about the ContentProvider, specifically, the authority under which it is
     * registered.
     */
    String packageName = mContext.getPackageName();
    String weatherProviderClassName = WeatherProvider.class.getName();
    ComponentName componentName = new ComponentName(packageName, weatherProviderClassName);

    try {

        /*
         * Get a reference to the package manager. The package manager allows us to access
         * information about packages installed on a particular device. In this case, we're
         * going to use it to get some information about our ContentProvider under test.
         */
        PackageManager pm = mContext.getPackageManager();

        /* The ProviderInfo will contain the authority, which is what we want to test */
        ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
        String actualAuthority = providerInfo.authority;
        String expectedAuthority = WeatherContract.CONTENT_AUTHORITY;

        /* Make sure that the registered authority matches the authority from the Contract */
        String incorrectAuthority =
                "Error: WeatherProvider registered with authority: " + actualAuthority +
                        " instead of expected authority: " + expectedAuthority;
        assertEquals(incorrectAuthority,
                actualAuthority,
                expectedAuthority);

    } catch (PackageManager.NameNotFoundException e) {
        String providerNotRegisteredAtAll =
                "Error: WeatherProvider not registered at " + mContext.getPackageName();
        /*
         * This exception is thrown if the ContentProvider hasn't been registered with the
         * manifest at all. If this is the case, you need to double check your
         * AndroidManifest file
         */
        fail(providerNotRegisteredAtAll);
    }
}