Skip to content

Commit

Permalink
[Versions] update to androidx dependencies. update to use new robolec…
Browse files Browse the repository at this point in the history
…tric/androidx dependencies.
  • Loading branch information
agrosner committed Oct 20, 2018
1 parent cbc30e7 commit fb3739c
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 142 deletions.
9 changes: 4 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
buildscript {
ext {
kotlin_version = '1.2.71'
target_sdk = 27
target_sdk = 28
min_sdk = 7
min_sdk_rx = 15
sql_cipher_min = 7
arch_min = 14
support_version = "28.0.0"

deps = [
kotlin : "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}",
Expand All @@ -18,17 +17,17 @@ buildscript {
javax_annotation : 'org.glassfish:javax.annotation:10.0-b28',
junit : 'junit:junit:4.12',
paging : "android.arch.paging:runtime:1.0.0",
support_annotations: "com.android.support:support-annotations:${support_version}",
support_annotations: "androidx.annotation:annotation:1.0.0",
]
}
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-alpha11'
classpath 'com.android.tools.build:gradle:3.3.0-beta01'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.3'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Sep 25 20:13:49 EDT 2018
#Mon Oct 15 17:14:01 EDT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dbflow5.migration

import android.support.annotation.CallSuper
import androidx.annotation.CallSuper
import com.dbflow5.appendQuotedIfNeeded
import com.dbflow5.config.FlowManager
import com.dbflow5.database.DatabaseWrapper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.dbflow5.transaction

import android.support.annotation.IntDef

import androidx.annotation.IntDef
import com.dbflow5.database.DatabaseWrapper

/**
Expand Down
26 changes: 14 additions & 12 deletions tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies {

kapt project("${dbflow_project_prefix}processor")
implementation project(':lib')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation project(':lib')
implementation project("${dbflow_project_prefix}sqlcipher")
implementation project(':reactive-streams')
Expand All @@ -58,21 +58,23 @@ dependencies {
kaptAndroidTest project("${dbflow_project_prefix}processor")

testImplementation deps.javax_annotation

testImplementation deps.junit
testImplementation "org.robolectric:robolectric:3.5.1"
testImplementation("com.nhaarman:mockito-kotlin:1.5.0") {
testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:2.0.0-RC3") {
exclude group: "org.jetbrains.kotlin"
}
testImplementation 'org.mockito:mockito-core:2.8.9'
testImplementation 'org.mockito:mockito-core:2.23.0'

androidTestImplementation deps.junit
androidTestImplementation('com.android.support.test:runner:0.5') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestImplementation('com.android.support.test:rules:0.5') {
exclude group: 'com.android.support', module: 'support-annotations'
}
testImplementation deps.junit
androidTestImplementation "androidx.test:core:1.0.0-beta02"
androidTestImplementation "androidx.test:runner:1.1.0-beta02"
androidTestImplementation "androidx.test:rules:1.1.0-beta02"
testImplementation "androidx.test:core:1.0.0-beta02"
testImplementation "androidx.test:runner:1.1.0-beta02"
testImplementation "androidx.test:rules:1.1.0-beta02"
testImplementation 'com.google.android:android-test:4.1.1.4'

testImplementation "org.robolectric:robolectric:4.0-beta-1"

}

android.applicationVariants.all { variant ->
Expand Down
1 change: 1 addition & 0 deletions tests/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
android.enableUnitTestBinaryResources=true
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.dbflow5

import com.dbflow5.AppDatabase
import com.dbflow5.DemoApp
import com.dbflow5.config.DBFlowDatabase
import com.dbflow5.config.DatabaseConfig
import com.dbflow5.config.FlowConfig
import com.dbflow5.config.FlowManager
import com.dbflow5.database.AndroidSQLiteOpenHelper
import com.dbflow5.prepackaged.PrepackagedDB
import com.dbflow5.provider.ContentDatabase
import com.dbflow5.runtime.ContentResolverNotifier
import com.dbflow5.sqlcipher.CipherDatabase
import org.junit.rules.TestRule
Expand All @@ -22,21 +21,25 @@ class DBFlowInstrumentedTestRule : TestRule {
@Throws(Throwable::class)
override fun evaluate() {
FlowManager.init(FlowConfig.Builder(DemoApp.context)
.database(DatabaseConfig(
databaseClass = AppDatabase::class.java,
openHelperCreator = AndroidSQLiteOpenHelper.createHelperCreator(DemoApp.context),
modelNotifier = ContentResolverNotifier(DemoApp.context, "com.grosner.content"),
transactionManagerCreator = { databaseDefinition: DBFlowDatabase ->
ImmediateTransactionManager(databaseDefinition)
}))
.database(DatabaseConfig(
openHelperCreator = AndroidSQLiteOpenHelper.createHelperCreator(DemoApp.context),
databaseClass = PrepackagedDB::class.java,
databaseName = "prepackaged"))
.database(DatabaseConfig(
openHelperCreator = AndroidSQLiteOpenHelper.createHelperCreator(DemoApp.context),
databaseClass = CipherDatabase::class.java))
.build())
.database(DatabaseConfig(
databaseClass = AppDatabase::class.java,
openHelperCreator = AndroidSQLiteOpenHelper.createHelperCreator(DemoApp.context),
modelNotifier = ContentResolverNotifier(DemoApp.context, "com.grosner.content"),
transactionManagerCreator = { databaseDefinition: DBFlowDatabase ->
ImmediateTransactionManager(databaseDefinition)
}))
.database(DatabaseConfig(
openHelperCreator = AndroidSQLiteOpenHelper.createHelperCreator(DemoApp.context),
databaseClass = PrepackagedDB::class.java,
databaseName = "prepackaged"))
.database(DatabaseConfig(
openHelperCreator = AndroidSQLiteOpenHelper.createHelperCreator(DemoApp.context),
databaseClass = CipherDatabase::class.java))
.database(DatabaseConfig.builder(ContentDatabase::class,
AndroidSQLiteOpenHelper.createHelperCreator(DemoApp.context))
.databaseName("content")
.build())
.build())
try {
base.evaluate()
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import com.dbflow5.structure.insert
import com.dbflow5.structure.save
import com.dbflow5.structure.update
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import java.util.concurrent.CountDownLatch
Expand All @@ -33,18 +32,18 @@ class ContentObserverTest : BaseInstrumentedUnitTest() {
@Before
fun setupUser() {
databaseForTable<User> {
(delete() from User::class).execute()
delete<User>().execute(this)
}
user = User(5, "Something", 55)
}

@Test
fun testSpecificUris() {
val conditionGroup = User::class.modelAdapter
.getPrimaryConditionClause(user)
.getPrimaryConditionClause(user)
val uri = getNotificationUri(contentUri,
User::class.java, ChangeAction.DELETE,
conditionGroup.conditions.toTypedArray())
User::class.java, ChangeAction.DELETE,
conditionGroup.conditions.toTypedArray())

assertEquals(uri.authority, contentUri)
assertEquals(tableName<User>(), uri.getQueryParameter(TABLE_QUERY_PARAM))
Expand All @@ -55,25 +54,25 @@ class ContentObserverTest : BaseInstrumentedUnitTest() {

@Test
fun testSpecificUrlInsert() {
assertProperConditions(ChangeAction.INSERT, { it.insert() })
assertProperConditions(ChangeAction.INSERT) { it.insert() }
}

@Test
fun testSpecificUrlUpdate() {
assertProperConditions(ChangeAction.UPDATE, { it.apply { age = 56 }.update() })
assertProperConditions(ChangeAction.UPDATE) { it.apply { age = 56 }.update() }

}

@Test
fun testSpecificUrlSave() {
// insert on SAVE
assertProperConditions(ChangeAction.INSERT, { it.apply { age = 57 }.save() })
assertProperConditions(ChangeAction.INSERT) { it.apply { age = 57 }.save() }
}

@Test
fun testSpecificUrlDelete() {
user.save()
assertProperConditions(ChangeAction.DELETE, { it.delete() })
assertProperConditions(ChangeAction.DELETE) { it.delete() }
}

private fun assertProperConditions(action: ChangeAction, userFunc: (User) -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
package com.dbflow5.provider

import android.content.ContentResolver
import android.content.pm.ProviderInfo
import com.dbflow5.BaseUnitTest
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import androidx.test.rule.provider.ProviderTestRule
import com.dbflow5.BaseInstrumentedUnitTest
import com.dbflow5.config.database
import com.dbflow5.query.Delete.Companion.table
import com.dbflow5.query.Delete.Companion.tables
import com.dbflow5.query.result
import com.dbflow5.query.select
import com.dbflow5.structure.exists
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Assert.*
import org.junit.Rule
import org.junit.Test
import org.robolectric.Robolectric
import org.robolectric.RuntimeEnvironment

/**
* Description:
*/
class ContentProviderTests : BaseUnitTest() {
private val mockContentResolver: ContentResolver
get() = RuntimeEnvironment.application.contentResolver
class ContentProviderTests : BaseInstrumentedUnitTest() {

@Before
fun setUp() {
val info = ProviderInfo()
info.authority = TestContentProvider.AUTHORITY
Robolectric.buildContentProvider(TestContentProvider_Provider::class.java).create(info)
}
@get:Rule
val contentProviderRule = ProviderTestRule.Builder(TestContentProvider_Provider::class.java, TestContentProvider.AUTHORITY).build()

private val mockContentResolver: ContentResolver
get() = ApplicationProvider.getApplicationContext<Context>().contentResolver

@Test
fun testContentProviderUtils() {
Expand Down Expand Up @@ -115,7 +110,7 @@ class ContentProviderTests : BaseUnitTest() {
assertEquals(testSyncableModel.name, "TestName")

testSyncableModel = (select from TestSyncableModel::class
where (TestSyncableModel_Table.id.`is`(testSyncableModel.id))).result!!
where (TestSyncableModel_Table.id.`is`(testSyncableModel.id))).result!!

var fromContentProvider = TestSyncableModel(id = testSyncableModel.id)
fromContentProvider = fromContentProvider.load(this)!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CipherTest : BaseInstrumentedUnitTest() {

@Test
fun testCipherModel() = database(CipherDatabase::class) {
(delete() from CipherModel::class).execute()
(delete() from CipherModel::class).execute(this)
val model = CipherModel(name = "name")
model.save(this)
assertTrue(model.exists(this))
Expand All @@ -24,6 +24,6 @@ class CipherTest : BaseInstrumentedUnitTest() {
where CipherModel_Table.name.eq("name"))
.result
assertTrue(retrieval!!.id == model.id)
(delete() from CipherModel::class).execute()
(delete() from CipherModel::class).execute(this)
}
}
10 changes: 4 additions & 6 deletions tests/src/test/java/com/dbflow5/BaseUnitTest.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package com.dbflow5

import android.content.Context
import androidx.test.core.app.ApplicationProvider
import androidx.test.runner.AndroidJUnit4
import org.junit.Rule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config

@RunWith(RobolectricTestRunner::class)
@Config(manifest = Config.NONE)
@RunWith(AndroidJUnit4::class)
abstract class BaseUnitTest {

@JvmField
@Rule
var dblflowTestRule = DBFlowTestRule.create()

val context: Context
get() = RuntimeEnvironment.application
get() = ApplicationProvider.getApplicationContext()
}
17 changes: 6 additions & 11 deletions tests/src/test/java/com/dbflow5/DBFlowTestRule.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package com.dbflow5

import android.content.Context
import androidx.test.core.app.ApplicationProvider
import com.dbflow5.config.DatabaseConfig
import com.dbflow5.config.FlowConfig
import com.dbflow5.config.FlowLog
import com.dbflow5.config.FlowManager
import com.dbflow5.database.AndroidSQLiteOpenHelper
import com.dbflow5.provider.ContentDatabase
import com.dbflow5.runtime.DirectModelNotifier
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
import org.robolectric.RuntimeEnvironment

class DBFlowTestRule : TestRule {

val context: Context
get() = RuntimeEnvironment.application
get() = ApplicationProvider.getApplicationContext()

override fun apply(base: Statement, description: Description): Statement {
return object : Statement() {
Expand All @@ -25,15 +24,11 @@ class DBFlowTestRule : TestRule {
override fun evaluate() {
FlowLog.setMinimumLoggingLevel(FlowLog.Level.V)
DirectModelNotifier().clearListeners()
FlowManager.init(FlowConfig.Builder(RuntimeEnvironment.application)
.database(DatabaseConfig.Builder(TestDatabase::class, AndroidSQLiteOpenHelper.createHelperCreator(context))
.transactionManagerCreator(::ImmediateTransactionManager2)
FlowManager.init(FlowConfig.Builder(context)
.database(DatabaseConfig.Builder(TestDatabase::class, AndroidSQLiteOpenHelper.createHelperCreator(context))
.transactionManagerCreator(::ImmediateTransactionManager2)
.build())
.build())
.database(DatabaseConfig.builder(ContentDatabase::class,
AndroidSQLiteOpenHelper.createHelperCreator(context))
.databaseName("content")
.build())
.build())
try {
base.evaluate()
} finally {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dbflow5.config

import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockitokotlin2.mock
import com.dbflow5.BaseUnitTest
import com.dbflow5.TestDatabase
import com.dbflow5.database.AndroidSQLiteOpenHelper
Expand Down
Loading

0 comments on commit fb3739c

Please sign in to comment.