Commit 71b368e2 authored by Ricki Hirner's avatar Ricki Hirner 🐑

Use GrantPermissionRule; update Kotlin

parent e3ff8b19
Pipeline #16582502 passed with stages
in 7 minutes and 34 seconds
buildscript {
ext.kotlin_version = '1.1.61'
ext.kotlin_version = '1.2.21'
ext.dokka_version = '0.9.15'
repositories {
......@@ -72,32 +72,11 @@ dependencies {
exclude group: 'com.fasterxml.jackson.core'
}
//noinspection GradleDynamicVersion
androidTestCompile 'com.android.support.test:runner:+'
//noinspection GradleDynamicVersion
androidTestCompile 'com.android.support.test:rules:+'
androidTestCompile 'com.android.support.test:runner:1.0.1'
androidTestCompile 'com.android.support.test:rules:1.0.1'
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'org.projectlombok:lombok:1.16.16'
testCompile 'junit:junit:4.12'
testCompile 'org.projectlombok:lombok:1.16.16'
}
// grant permissions for unit tests
task grantPermissions(dependsOn: 'installDebugAndroidTest') {
doLast {
def adb = android.getAdbExe().toString()
[
'android.permission.READ_CONTACTS',
'android.permission.WRITE_CONTACTS'
].each {
"${adb} shell pm grant at.bitfire.vcard4android.test ${it}".execute()
}
}
}
tasks.whenTaskAdded { task ->
if (task.name.startsWith('connectedDebugAndroidTest')) {
task.dependsOn grantPermissions
}
}
......@@ -13,10 +13,11 @@ import android.accounts.Account;
import android.content.ContentProviderClient;
import android.content.ContentValues;
import android.provider.ContactsContract;
import android.support.annotation.RequiresPermission;
import android.support.test.rule.GrantPermissionRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import java.util.Arrays;
......@@ -31,11 +32,14 @@ import static org.junit.Assert.assertTrue;
public class AndroidAddressBookTest {
final Account testAccount = new Account("AndroidAddressBookTest", "at.bitfire.vcard4android");
@Rule
public GrantPermissionRule permissionRule =
GrantPermissionRule.grant(Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS);
final Account testAccount = new Account("AndroidAddressBookTest", "at.bitfire.vcard4android");
ContentProviderClient provider;
@Before
@RequiresPermission(allOf = { Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS })
public void connect() throws Exception {
provider = getContext().getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY);
assertNotNull(provider);
......
......@@ -13,10 +13,12 @@ import android.accounts.Account;
import android.content.ContentProviderClient;
import android.provider.ContactsContract;
import android.support.annotation.RequiresPermission;
import android.support.test.rule.GrantPermissionRule;
import android.util.Base64;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
......@@ -42,13 +44,16 @@ import static org.junit.Assert.assertTrue;
public class AndroidContactTest {
@Rule
public GrantPermissionRule permissionRule =
GrantPermissionRule.grant(Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS);
final Account testAccount = new Account("AndroidContactTest", "at.bitfire.vcard4android");
ContentProviderClient provider;
AndroidAddressBook addressBook;
@Before
@RequiresPermission(allOf = { Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS })
public void connect() throws Exception {
provider = getContext().getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY);
assertNotNull(provider);
......
......@@ -12,10 +12,11 @@ import android.Manifest;
import android.accounts.Account;
import android.content.ContentProviderClient;
import android.provider.ContactsContract;
import android.support.annotation.RequiresPermission;
import android.support.test.rule.GrantPermissionRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import java.io.FileNotFoundException;
......@@ -29,13 +30,16 @@ import static org.junit.Assert.assertNotNull;
public class AndroidGroupTest {
@Rule
public GrantPermissionRule permissionRule =
GrantPermissionRule.grant(Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS);
final Account testAccount = new Account("AndroidContactGroupTest", "at.bitfire.vcard4android");
ContentProviderClient provider;
AndroidAddressBook addressBook;
@Before
@RequiresPermission(allOf = { Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS })
public void connect() throws Exception {
provider = getContext().getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY);
assertNotNull(provider);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment