Commit 37a8021a authored by Ricki Hirner's avatar Ricki Hirner

Upgrade to ez-vcard/0.10.0; switch to Android JUnit4 tests

parent b695eab1
Pipeline #4562150 passed with stage
in 11 minutes and 8 seconds
image: registry.gitlab.com/bitfireat/davdroid:latest
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
- chmod +x gradlew
- export GRADLE_USER_HOME=`pwd`/.gradle; chmod +x gradlew
- emulator64-arm -avd test -no-skin -no-audio -no-window & wait-for-emulator.sh
cache:
......@@ -12,7 +11,7 @@ cache:
test:
script:
- ./gradlew -i check connectedCheck
- ./gradlew check connectedCheck
artifacts:
paths:
- build/outputs/lint-results-debug.html
......
......@@ -43,6 +43,10 @@ android {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
dependencies {
......@@ -50,7 +54,7 @@ dependencies {
provided 'org.projectlombok:lombok:1.16.10'
// ez-vcard to parse/generate VCards
compile('com.googlecode.ez-vcard:ez-vcard:0.9.11') {
compile('com.googlecode.ez-vcard:ez-vcard:0.10.0') {
// hCard functionality not needed
exclude group: 'org.jsoup'
exclude group: 'org.freemarker'
......@@ -58,6 +62,10 @@ dependencies {
exclude group: 'com.fasterxml.jackson.core'
}
androidTestCompile 'com.android.support.test:runner:0.5+'
androidTestCompile 'com.android.support.test:rules:0.5+'
androidTestCompile 'junit:junit:4.12'
testCompile 'junit:junit:4.12'
}
......
org.gradle.jvmargs=-Xmx1536M
......@@ -8,33 +8,44 @@
package at.bitfire.vcard4android;
import android.Manifest;
import android.accounts.Account;
import android.content.ContentProviderClient;
import android.content.ContentValues;
import android.content.Context;
import android.provider.ContactsContract;
import android.test.InstrumentationTestCase;
import android.support.annotation.RequiresPermission;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
public class AndroidAddressBookTest extends InstrumentationTestCase {
import static android.support.test.InstrumentationRegistry.getContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class AndroidAddressBookTest {
final Account testAccount = new Account("AndroidAddressBookTest", "at.bitfire.vcard4android");
ContentProviderClient provider;
@Override
protected void setUp() throws Exception {
Context context = getInstrumentation().getContext();
provider = context.getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY);
@Before
@RequiresPermission(allOf = { Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS })
public void connect() throws Exception {
provider = getContext().getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY);
assertNotNull(provider);
}
@Override
public void tearDown() throws Exception {
@After
public void disconnect() throws Exception {
provider.release();
}
@Test
public void testSettings() throws ContactsStorageException {
AndroidAddressBook addressBook = new AndroidAddressBook(testAccount, provider, AndroidGroupFactory.INSTANCE, AndroidContactFactory.INSTANCE);
......@@ -55,7 +66,8 @@ public class AndroidAddressBookTest extends InstrumentationTestCase {
assertTrue(values.getAsInteger(ContactsContract.Settings.UNGROUPED_VISIBLE) != 0);
}
public void testSyncState() throws ContactsStorageException {
@Test
public void testSyncState() throws ContactsStorageException {
AndroidAddressBook addressBook = new AndroidAddressBook(testAccount, provider, AndroidGroupFactory.INSTANCE, AndroidContactFactory.INSTANCE);
addressBook.setSyncState(new byte[0]);
......
......@@ -8,49 +8,53 @@
package at.bitfire.vcard4android;
import android.Manifest;
import android.accounts.Account;
import android.content.ContentProviderClient;
import android.content.Context;
import android.provider.ContactsContract;
import android.test.InstrumentationTestCase;
import android.util.Log;
import android.support.annotation.RequiresPermission;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Level;
import ezvcard.Ezvcard;
import ezvcard.VCardVersion;
import ezvcard.io.text.VCardWriter;
import ezvcard.property.Address;
import ezvcard.property.Email;
import lombok.Cleanup;
public class AndroidContactTest extends InstrumentationTestCase {
import static android.support.test.InstrumentationRegistry.getContext;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class AndroidContactTest {
final Account testAccount = new Account("AndroidContactTest", "at.bitfire.vcard4android");
ContentProviderClient provider;
AndroidAddressBook addressBook;
@Override
protected void setUp() throws Exception {
Context context = getInstrumentation().getContext();
provider = context.getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY);
@Before
@RequiresPermission(allOf = { Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS })
public void connect() throws Exception {
provider = getContext().getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY);
assertNotNull(provider);
addressBook = new AndroidAddressBook(testAccount, provider, AndroidGroupFactory.INSTANCE, AndroidContactFactory.INSTANCE);
}
@Override
public void tearDown() throws Exception {
@After
public void disconnect() throws Exception {
provider.release();
}
@Test
public void testAddAndReadContact() throws FileNotFoundException, ContactsStorageException {
Contact vcard = new Contact();
vcard.displayName = "Mya Contact";
......@@ -77,6 +81,7 @@ public class AndroidContactTest extends InstrumentationTestCase {
assertEquals(vcard2.phoneticFamilyName, vcard.phoneticFamilyName);
}
@Test
public void testLargeTransaction() throws FileNotFoundException, ContactsStorageException {
Contact vcard = new Contact();
vcard.displayName = "Large Transaction";
......@@ -91,7 +96,7 @@ public class AndroidContactTest extends InstrumentationTestCase {
assertEquals(4000, vcard2.emails.size());
}
@Test
public void testAddressCaretEncoding() throws IOException {
Address address = new Address();
address.setLabel("My \"Label\"\nLine 2");
......@@ -115,20 +120,24 @@ public class AndroidContactTest extends InstrumentationTestCase {
ByteArrayOutputStream os = new ByteArrayOutputStream();
contact.write(VCardVersion.V4_0, GroupMethod.GROUP_VCARDS, true, os);
assertTrue(os.toString().contains("ADR;LABEL=My ^'Label^'^nLine 2:;;Street \"Address\";;;;"));
Constants.log.info(os.toString());
assertTrue(os.toString().contains("ADR;LABEL=My ^'Label^'\\nLine 2:;;Street \"Address\";;;;"));
}
@Test
public void testLabelToXName() {
assertEquals("X-AUNTIES_HOME", AndroidContact.labelToXName("auntie's home"));
}
@Test
public void testToURIScheme() {
assertEquals("testp+csfgh-ewt4345.2qiuz4", AndroidContact.toURIScheme("02 34test#ä{☺}ö p[]ß+csfgh()-e_wt4\\345.2qiuz4"));
assertEquals("CyanogenModForum", AndroidContact.toURIScheme("CyanogenMod Forum"));
assertEquals("CyanogenModForum", AndroidContact.toURIScheme("CyanogenMod_Forum"));
}
@Test
public void testXNameToLabel() {
assertEquals("Aunties Home", AndroidContact.xNameToLabel("X-AUNTIES_HOME"));
}
......
......@@ -8,56 +8,65 @@
package at.bitfire.vcard4android;
import android.Manifest;
import android.accounts.Account;
import android.content.ContentProviderClient;
import android.content.Context;
import android.provider.ContactsContract;
import android.test.InstrumentationTestCase;
import android.support.annotation.RequiresPermission;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.FileNotFoundException;
public class AndroidGroupTest extends InstrumentationTestCase {
import static android.support.test.InstrumentationRegistry.getContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class AndroidGroupTest {
final Account testAccount = new Account("AndroidContactGroupTest", "at.bitfire.vcard4android");
ContentProviderClient provider;
final Account testAccount = new Account("AndroidContactGroupTest", "at.bitfire.vcard4android");
ContentProviderClient provider;
AndroidAddressBook addressBook;
AndroidAddressBook addressBook;
@Override
protected void setUp() throws Exception {
Context context = getInstrumentation().getContext();
provider = context.getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY);
assertNotNull(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);
addressBook = new AndroidAddressBook(testAccount, provider, AndroidGroupFactory.INSTANCE, AndroidContactFactory.INSTANCE);
}
addressBook = new AndroidAddressBook(testAccount, provider, AndroidGroupFactory.INSTANCE, AndroidContactFactory.INSTANCE);
}
@Override
public void tearDown() throws Exception {
provider.release();
}
@After
public void disconnect() throws Exception {
provider.release();
}
public void testCreateReadDeleteGroup() throws FileNotFoundException, ContactsStorageException {
Contact contact = new Contact();
contact.displayName = "at.bitfire.vcard4android-AndroidGroupTest";
contact.note = "(test group)";
@Test
public void testCreateReadDeleteGroup() throws FileNotFoundException, ContactsStorageException {
Contact contact = new Contact();
contact.displayName = "at.bitfire.vcard4android-AndroidGroupTest";
contact.note = "(test group)";
// ensure we start without this group
assertEquals(0, addressBook.queryGroups(ContactsContract.Groups.TITLE + "=?", new String[] { contact.displayName }).length);
// ensure we start without this group
assertEquals(0, addressBook.queryGroups(ContactsContract.Groups.TITLE + "=?", new String[] { contact.displayName }).length);
// create group
AndroidGroup group = new AndroidGroup(addressBook, contact, null, null);
group.create();
AndroidGroup[] groups = addressBook.queryGroups(ContactsContract.Groups.TITLE + "=?", new String[] { contact.displayName } );
assertEquals(1, groups.length);
Contact contact2 = groups[0].getContact();
assertEquals(contact.displayName, contact2.displayName);
assertEquals(contact.note, contact2.note);
// create group
AndroidGroup group = new AndroidGroup(addressBook, contact, null, null);
group.create();
AndroidGroup[] groups = addressBook.queryGroups(ContactsContract.Groups.TITLE + "=?", new String[] { contact.displayName } );
assertEquals(1, groups.length);
Contact contact2 = groups[0].getContact();
assertEquals(contact.displayName, contact2.displayName);
assertEquals(contact.note, contact2.note);
// delete group
group.delete();
assertEquals(0, addressBook.queryGroups(ContactsContract.Groups.TITLE + "=?", new String[] { contact.displayName }).length);
}
// delete group
group.delete();
assertEquals(0, addressBook.queryGroups(ContactsContract.Groups.TITLE + "=?", new String[] { contact.displayName }).length);
}
}
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