AndroidTestCase - assertActivityRequiresPermission and assertReadingContentUriRequiresPermission
<p>hoping for some help with the methods assertActivityRequiresPermission and assertReadingContentUriRequiresPermission. It's not behaving the way I thought it will and I'm not seeing where I went wrong.</p>

<p>My understanding is that both activities and providers can be protected by adding android:permission to their respective tags (  and  ) in AndroidManifest.xml. To declare that a client activity has the required permission to start and activity or work with a provider, we declare  under the  tag in what I believe to be at a 'package' level.</p>

<p>So to test how the assert methods in AndroidTestCase works I set up a HelloWorld project and a project to test HelloWorld. This is the manifest for HelloWorld.</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.helloandroid"
  android:versionCode="1"
  android:versionName="1.0"&gt;
&lt;uses-sdk android:minSdkVersion="8" /&gt;

&lt;uses-permission android:name="android.permission.RECEIVE_SMS" /&gt;

&lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
    &lt;activity android:name=".HelloAndroidActivity"
              android:label="@string/app_name"&gt;
        &lt;intent-filter&gt;
            &lt;action android:name="android.intent.action.MAIN" /&gt;
            &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
        &lt;/intent-filter&gt;
    &lt;/activity&gt;

    &lt;activity android:name=".RecipientActivity"
              android:label="@string/app_name"
              android:permission="android.permission.RECEIVE_SMS" &gt;
    &lt;/activity&gt;
&lt;/application&gt;
&lt;/manifest&gt;
</code></pre>

<p>I have RecipientActivity protected by RECEIVE_SMS, so I declare using RECEIVE_SMS so that HelloAndroidActivity is able to start RecipientActivity.</p>

<p>Now in my test class,</p>

<pre><code>public class TestRecipientActivity extends AndroidTestCase {

    public void testPermissions() {
        String packageName = "com.example.helloandroid";
        String className = packageName + ".RecipientActivity";
        String permission = android.Manifest.permission.RECEIVE_SMS;
        assertActivityRequiresPermission(packageName, className, permission);
    }

    public void testContactsPermissions() {
        final Uri URI = ContactsContract.AUTHORITY_URI;
        final String permission = android.Manifest.permission.READ_CONTACTS;
        assertReadingContentUriRequiresPermission(URI, permission);
     }
}
</code></pre>

<p>Results?</p>

<p>testPermissions() fails with 'AssertionFailError: expected security exception', meaning RecipientActivity is started successfully with no SecurityException thrown. </p>

<p>testContactsPermissions() passed without throwing any exception although I do not have define  anywhere. </p>

<p>Can anyone explain why I'm getting the above results? Thanks!</p>
