Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package at.bitfire.vcard4android
package at.bitfire.synctools.mapping.contacts

object TestUtils {

Expand All @@ -16,4 +16,4 @@ object TestUtils {
fun resourceToByteArray(resource: String): ByteArray =
this::class.java.getResourceAsStream(resource)!!.use { it.readBytes() }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package at.bitfire.vcard4android.contactrow
package at.bitfire.synctools.mapping.contacts.builder

import android.Manifest
import android.accounts.Account
Expand All @@ -16,11 +16,14 @@ import android.provider.ContactsContract
import android.provider.ContactsContract.RawContacts
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
import at.bitfire.vcard4android.AndroidContact
import at.bitfire.vcard4android.Contact
import at.bitfire.vcard4android.TestUtils
import at.bitfire.vcard4android.impl.TestAddressBook
import org.junit.Assert.*
import at.bitfire.synctools.mapping.contacts.Contact
import at.bitfire.synctools.mapping.contacts.TestUtils
import at.bitfire.synctools.storage.contacts.AndroidContact
import at.bitfire.synctools.storage.contacts.TestAddressBook
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.BeforeClass
import org.junit.ClassRule
import org.junit.Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package at.bitfire.vcard4android.contactrow
package at.bitfire.synctools.mapping.contacts.handler

import android.Manifest
import android.accounts.Account
Expand All @@ -16,16 +16,22 @@ import android.provider.ContactsContract.CommonDataKinds.Photo
import android.provider.ContactsContract.RawContacts
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
import at.bitfire.vcard4android.AndroidContact
import at.bitfire.vcard4android.Contact
import at.bitfire.vcard4android.TestUtils
import at.bitfire.vcard4android.impl.TestAddressBook
import at.bitfire.synctools.mapping.contacts.Contact
import at.bitfire.synctools.mapping.contacts.TestUtils
import at.bitfire.synctools.storage.contacts.AndroidContact
import at.bitfire.synctools.storage.contacts.TestAddressBook
import org.junit.Assert
import org.junit.Assert.*
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.BeforeClass
import org.junit.ClassRule
import org.junit.Test
import java.util.*
import java.util.Arrays

class PhotoHandlerTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package at.bitfire.vcard4android
package at.bitfire.synctools.storage.contacts

import android.Manifest
import android.accounts.Account
Expand All @@ -13,7 +13,7 @@ import android.content.ContentValues
import android.provider.ContactsContract
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
import at.bitfire.vcard4android.impl.TestAddressBook
import at.bitfire.synctools.mapping.contacts.Contact
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package at.bitfire.vcard4android
package at.bitfire.synctools.storage.contacts

import android.Manifest
import android.accounts.Account
Expand All @@ -14,10 +14,10 @@ import android.util.Base64
import androidx.test.filters.MediumTest
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
import at.bitfire.synctools.mapping.contacts.Contact
import at.bitfire.synctools.mapping.contacts.LabeledProperty
import at.bitfire.synctools.storage.LocalStorageException
import at.bitfire.vcard4android.impl.TestAddressBook
import at.bitfire.vcard4android.impl.testProductId
import at.bitfire.vcard4android.property.XAbDate
import at.bitfire.synctools.vcard.property.XAbDate
import ezvcard.VCardVersion
import ezvcard.property.Address
import ezvcard.property.Birthday
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package at.bitfire.vcard4android
package at.bitfire.synctools.storage.contacts

import android.Manifest
import android.accounts.Account
import android.content.ContentProviderClient
import android.provider.ContactsContract
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
import at.bitfire.vcard4android.impl.TestAddressBook
import at.bitfire.synctools.mapping.contacts.Contact
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package at.bitfire.vcard4android.impl
package at.bitfire.synctools.storage.contacts

val testProductId = "bitfireAT/synctools test"
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package at.bitfire.vcard4android.impl
package at.bitfire.synctools.storage.contacts

import android.accounts.Account
import android.content.ContentProviderClient
import android.content.ContentValues
import at.bitfire.vcard4android.*

class TestAddressBook(
account: Account,
provider: ContentProviderClient
account: Account,
provider: ContentProviderClient
): AndroidAddressBook<AndroidContact, AndroidGroup>(account, provider, ContactFactory, GroupFactory) {

object ContactFactory: AndroidContactFactory<AndroidContact> {
Expand All @@ -30,5 +29,5 @@ class TestAddressBook(
AndroidGroup(addressBook, values)

}

}
30 changes: 30 additions & 0 deletions lib/src/androidTest/kotlin/at/bitfire/synctools/util/UtilsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file is part of bitfireAT/synctools which is released under GPLv3.
* Copyright © All Contributors. See the LICENSE and AUTHOR files in the root directory for details.
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package at.bitfire.synctools.util

import at.bitfire.synctools.util.Utils.capitalize
import at.bitfire.synctools.util.Utils.trimToNull
import org.junit.Assert
import org.junit.Test

class UtilsTest {
@Test
fun testCapitalize() {
Assert.assertEquals("Utils Test", "utils test".capitalize()) // Test multiple words
Assert.assertEquals("Utils", "utils".capitalize()) // Test single word
Assert.assertEquals("", "".capitalize()) // Test empty string
}

@Test
fun testTrimToNull() {
Assert.assertEquals("test", " test".trimToNull()) // Test spaces only before
Assert.assertEquals("test", "test ".trimToNull()) // Test spaces only after
Assert.assertEquals("test", " test ".trimToNull()) // Test spaces before and after
Assert.assertNull(" ".trimToNull()) // Test spaces
Assert.assertNull("".trimToNull()) // Test empty string
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package at.bitfire.vcard4android
package at.bitfire.synctools.vcard

import ezvcard.Ezvcard
import ezvcard.VCard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
package at.bitfire.synctools.icalendar

import androidx.annotation.VisibleForTesting
import at.bitfire.vcard4android.Utils.trimToNull
import at.bitfire.synctools.util.Utils.trimToNull
import net.fortuna.ical4j.data.CalendarOutputter
import net.fortuna.ical4j.model.Calendar
import net.fortuna.ical4j.model.Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package at.bitfire.synctools.mapping.calendar.builder

import android.content.Entity
import android.provider.CalendarContract.Events
import at.bitfire.vcard4android.Utils.trimToNull
import at.bitfire.synctools.util.Utils.trimToNull
import net.fortuna.ical4j.model.component.VEvent

class DescriptionBuilder: AndroidEntityBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package at.bitfire.synctools.mapping.calendar.builder

import android.content.Entity
import android.provider.CalendarContract.Events
import at.bitfire.vcard4android.Utils.trimToNull
import at.bitfire.synctools.util.Utils.trimToNull
import net.fortuna.ical4j.model.component.VEvent

class LocationBuilder: AndroidEntityBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package at.bitfire.synctools.mapping.calendar.builder

import android.content.Entity
import android.provider.CalendarContract.Events
import at.bitfire.vcard4android.Utils.trimToNull
import at.bitfire.synctools.util.Utils.trimToNull
import net.fortuna.ical4j.model.component.VEvent

class TitleBuilder: AndroidEntityBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package at.bitfire.synctools.mapping.calendar.handler
import android.content.Entity
import android.provider.CalendarContract.Events
import at.bitfire.synctools.icalendar.plusAssign
import at.bitfire.vcard4android.Utils.trimToNull
import at.bitfire.synctools.util.Utils.trimToNull
import net.fortuna.ical4j.model.component.VEvent
import net.fortuna.ical4j.model.property.Description

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package at.bitfire.synctools.mapping.calendar.handler
import android.content.Entity
import android.provider.CalendarContract.Events
import at.bitfire.synctools.icalendar.plusAssign
import at.bitfire.vcard4android.Utils.trimToNull
import at.bitfire.synctools.util.Utils.trimToNull
import net.fortuna.ical4j.model.component.VEvent
import net.fortuna.ical4j.model.property.Location

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package at.bitfire.synctools.mapping.calendar.handler
import android.content.Entity
import android.provider.CalendarContract.Events
import at.bitfire.synctools.icalendar.plusAssign
import at.bitfire.vcard4android.Utils.trimToNull
import at.bitfire.synctools.util.Utils.trimToNull
import net.fortuna.ical4j.model.component.VEvent
import net.fortuna.ical4j.model.property.Summary

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package at.bitfire.vcard4android
package at.bitfire.synctools.mapping.contacts

import at.bitfire.vcard4android.property.CustomScribes.registerCustomScribes
import at.bitfire.vcard4android.property.XAbDate
import at.bitfire.synctools.vcard.property.CustomScribes.registerCustomScribes
import at.bitfire.synctools.vcard.property.XAbDate
import com.google.common.base.Ascii
import com.google.common.base.MoreObjects
import ezvcard.VCardVersion
Expand Down Expand Up @@ -37,7 +37,7 @@ import java.util.LinkedList
* vCards are parsed to [Contact]s by [ContactReader].
* [Contact]s are written to vCards by [ContactWriter].
*
* [Contact]s are written to and read from the Android storage by [AndroidContact].
* [Contact]s are written to and read from the Android storage by [at.bitfire.synctools.storage.contacts.AndroidContact].
*/
data class Contact(
var uid: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,41 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package at.bitfire.vcard4android.contactrow
package at.bitfire.synctools.mapping.contacts

import android.content.ContentProviderClient
import android.content.ContentValues
import android.net.Uri
import android.provider.ContactsContract.RawContacts
import at.bitfire.synctools.storage.ContactsBatchOperation
import at.bitfire.vcard4android.AndroidContact
import at.bitfire.vcard4android.Contact
import at.bitfire.synctools.mapping.contacts.builder.DataRowBuilder
import at.bitfire.synctools.mapping.contacts.builder.EmailBuilder
import at.bitfire.synctools.mapping.contacts.builder.EventBuilder
import at.bitfire.synctools.mapping.contacts.builder.ImBuilder
import at.bitfire.synctools.mapping.contacts.builder.NicknameBuilder
import at.bitfire.synctools.mapping.contacts.builder.NoteBuilder
import at.bitfire.synctools.mapping.contacts.builder.OrganizationBuilder
import at.bitfire.synctools.mapping.contacts.builder.PhoneBuilder
import at.bitfire.synctools.mapping.contacts.builder.PhotoBuilder
import at.bitfire.synctools.mapping.contacts.builder.RelationBuilder
import at.bitfire.synctools.mapping.contacts.builder.SipAddressBuilder
import at.bitfire.synctools.mapping.contacts.builder.StructuredNameBuilder
import at.bitfire.synctools.mapping.contacts.builder.StructuredPostalBuilder
import at.bitfire.synctools.mapping.contacts.builder.WebsiteBuilder
import at.bitfire.synctools.mapping.contacts.handler.DataRowHandler
import at.bitfire.synctools.mapping.contacts.handler.EmailHandler
import at.bitfire.synctools.mapping.contacts.handler.EventHandler
import at.bitfire.synctools.mapping.contacts.handler.ImHandler
import at.bitfire.synctools.mapping.contacts.handler.NicknameHandler
import at.bitfire.synctools.mapping.contacts.handler.NoteHandler
import at.bitfire.synctools.mapping.contacts.handler.OrganizationHandler
import at.bitfire.synctools.mapping.contacts.handler.PhoneHandler
import at.bitfire.synctools.mapping.contacts.handler.PhotoHandler
import at.bitfire.synctools.mapping.contacts.handler.RelationHandler
import at.bitfire.synctools.mapping.contacts.handler.SipAddressHandler
import at.bitfire.synctools.mapping.contacts.handler.StructuredNameHandler
import at.bitfire.synctools.mapping.contacts.handler.StructuredPostalHandler
import at.bitfire.synctools.mapping.contacts.handler.WebsiteHandler
import at.bitfire.synctools.storage.contacts.ContactsBatchOperation
import java.util.logging.Level
import java.util.logging.Logger

Expand Down Expand Up @@ -77,7 +103,7 @@ class ContactProcessor(


fun handleRawContact(values: ContentValues, contact: Contact) {
contact.uid = values.getAsString(AndroidContact.COLUMN_UID)
contact.uid = values.getAsString(at.bitfire.synctools.storage.contacts.AndroidContact.COLUMN_UID)
}

fun handleDataRow(values: ContentValues, contact: Contact) {
Expand Down Expand Up @@ -109,4 +135,4 @@ class ContactProcessor(
return mimeTypes
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package at.bitfire.vcard4android

import at.bitfire.vcard4android.Utils.trimToNull
import at.bitfire.vcard4android.property.CustomScribes.registerCustomScribes
import at.bitfire.vcard4android.property.CustomType
import at.bitfire.vcard4android.property.XAbDate
import at.bitfire.vcard4android.property.XAbLabel
import at.bitfire.vcard4android.property.XAbRelatedNames
import at.bitfire.vcard4android.property.XPhoneticFirstName
import at.bitfire.vcard4android.property.XPhoneticLastName
import at.bitfire.vcard4android.property.XPhoneticMiddleName
import at.bitfire.vcard4android.property.XSip
package at.bitfire.synctools.mapping.contacts

import at.bitfire.synctools.util.Utils.trimToNull
import at.bitfire.synctools.vcard.property.CustomScribes.registerCustomScribes
import at.bitfire.synctools.vcard.property.CustomType
import at.bitfire.synctools.vcard.property.XAbDate
import at.bitfire.synctools.vcard.property.XAbLabel
import at.bitfire.synctools.vcard.property.XAbRelatedNames
import at.bitfire.synctools.vcard.property.XPhoneticFirstName
import at.bitfire.synctools.vcard.property.XPhoneticLastName
import at.bitfire.synctools.vcard.property.XPhoneticMiddleName
import at.bitfire.synctools.vcard.property.XSip
import ezvcard.Ezvcard
import ezvcard.VCard
import ezvcard.parameter.RelatedType
Expand Down
Loading
Loading