mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
Tech | Kotlin update + other dependencies (#2079)
This commit is contained in:
parent
5e5a34f824
commit
a0aa9da19d
19 changed files with 151 additions and 157 deletions
|
@ -19,6 +19,21 @@ android {
|
|||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_11
|
||||
targetCompatibility JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
testOptions {
|
||||
unitTests {
|
||||
includeAndroidResources = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@ -39,8 +54,6 @@ dependencies {
|
|||
implementation databaseDependencies.roomKtx
|
||||
|
||||
kapt databaseDependencies.annotations
|
||||
// Current workaround for ROOM on MAC M1 issue.
|
||||
kapt("org.xerial:sqlite-jdbc:3.34.0")
|
||||
|
||||
implementation applicationDependencies.timber
|
||||
|
||||
|
|
|
@ -9,14 +9,14 @@ import com.anytypeio.anytype.persistence.model.AccountTable
|
|||
abstract class AccountDao : BaseDao<AccountTable> {
|
||||
|
||||
@Query(Config.CLEAR_ACCOUNT_TABLE)
|
||||
abstract suspend fun clear()
|
||||
abstract fun clear()
|
||||
|
||||
@Query(Config.QUERY_LAST_ACCOUNT)
|
||||
abstract suspend fun lastAccount(): List<AccountTable>
|
||||
abstract fun lastAccount(): List<AccountTable>
|
||||
|
||||
@Query(Config.QUERY_ACCOUNT_BY_ID)
|
||||
abstract suspend fun getAccount(id: String): AccountTable?
|
||||
abstract fun getAccount(id: String): AccountTable?
|
||||
|
||||
@Query(Config.GET_ACCOUNTS)
|
||||
abstract suspend fun getAccounts(): List<AccountTable>
|
||||
abstract fun getAccounts(): List<AccountTable>
|
||||
}
|
|
@ -11,7 +11,7 @@ interface BaseDao<T> {
|
|||
* @param obj the object to be inserted.
|
||||
*/
|
||||
@Insert
|
||||
suspend fun insert(obj: T)
|
||||
fun insert(obj: T)
|
||||
|
||||
/**
|
||||
* Insert an array of objects in the database.
|
||||
|
@ -19,7 +19,7 @@ interface BaseDao<T> {
|
|||
* @param obj the objects to be inserted.
|
||||
*/
|
||||
@Insert
|
||||
suspend fun insert(objects: List<T>)
|
||||
fun insert(objects: List<T>)
|
||||
|
||||
/**
|
||||
* Update an object from the database.
|
||||
|
@ -27,7 +27,7 @@ interface BaseDao<T> {
|
|||
* @param obj the object to be updated
|
||||
*/
|
||||
@Update
|
||||
suspend fun update(obj: T)
|
||||
fun update(obj: T)
|
||||
|
||||
/**
|
||||
* Delete an object from the database
|
||||
|
@ -35,5 +35,5 @@ interface BaseDao<T> {
|
|||
* @param obj the object to be deleted
|
||||
*/
|
||||
@Delete
|
||||
suspend fun delete(obj: T)
|
||||
fun delete(obj: T)
|
||||
}
|
|
@ -1,85 +1,85 @@
|
|||
package com.anytypeio.anytype
|
||||
|
||||
//import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||
//import androidx.room.Room
|
||||
//import androidx.test.platform.app.InstrumentationRegistry
|
||||
//import com.anytypeio.anytype.persistence.db.AnytypeDatabase
|
||||
//import com.anytypeio.anytype.persistence.model.AccountTable
|
||||
//import kotlinx.coroutines.delay
|
||||
//import kotlinx.coroutines.runBlocking
|
||||
//import org.junit.After
|
||||
//import org.junit.Rule
|
||||
//import org.junit.Test
|
||||
//import org.junit.runner.RunWith
|
||||
//import org.robolectric.RobolectricTestRunner
|
||||
//import org.robolectric.annotation.Config
|
||||
//import kotlin.test.assertEquals
|
||||
//import kotlin.test.assertTrue
|
||||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||
import androidx.room.Room
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.anytypeio.anytype.persistence.db.AnytypeDatabase
|
||||
import com.anytypeio.anytype.persistence.model.AccountTable
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.After
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
//@RunWith(RobolectricTestRunner::class)
|
||||
//@Config(manifest = Config.NONE)
|
||||
//class AccountDaoTest {
|
||||
//
|
||||
// @get:Rule
|
||||
// val instantTaskExecutorRule = InstantTaskExecutorRule()
|
||||
//
|
||||
// private val database = Room.inMemoryDatabaseBuilder(
|
||||
// InstrumentationRegistry.getInstrumentation().context,
|
||||
// AnytypeDatabase::class.java
|
||||
// ).allowMainThreadQueries().build()
|
||||
//
|
||||
// @After
|
||||
// fun after() {
|
||||
// database.close()
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// fun `should return empty list if there are no last account in db`() {
|
||||
// runBlocking {
|
||||
// val accounts = database.accountDao().lastAccount()
|
||||
// assertTrue { accounts.isEmpty() }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// fun `should return last account`() = runBlocking {
|
||||
//
|
||||
// val firstAccount = AccountTable(
|
||||
// id = MockDataFactory.randomString(),
|
||||
// name = MockDataFactory.randomString(),
|
||||
// timestamp = System.currentTimeMillis()
|
||||
// )
|
||||
//
|
||||
// delay(1)
|
||||
//
|
||||
// val secondAccount = AccountTable(
|
||||
// id = MockDataFactory.randomString(),
|
||||
// name = MockDataFactory.randomString(),
|
||||
// timestamp = System.currentTimeMillis()
|
||||
// )
|
||||
//
|
||||
// database.accountDao().insert(firstAccount)
|
||||
// database.accountDao().insert(secondAccount)
|
||||
//
|
||||
// val result = database.accountDao().lastAccount()
|
||||
//
|
||||
// assertTrue { result.size == 1 }
|
||||
// assertTrue { result.first() == secondAccount }
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// fun `should return expected account when queried using account id`() = runBlocking {
|
||||
//
|
||||
// val account = AccountTable(
|
||||
// id = MockDataFactory.randomString(),
|
||||
// name = MockDataFactory.randomString(),
|
||||
// timestamp = System.currentTimeMillis()
|
||||
// )
|
||||
//
|
||||
// database.accountDao().insert(account)
|
||||
//
|
||||
// val result = database.accountDao().getAccount(account.id)
|
||||
//
|
||||
// assertEquals(account, result)
|
||||
// }
|
||||
//}
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(manifest = Config.NONE)
|
||||
class AccountDaoTest {
|
||||
|
||||
@get:Rule
|
||||
val instantTaskExecutorRule = InstantTaskExecutorRule()
|
||||
|
||||
private val database = Room.inMemoryDatabaseBuilder(
|
||||
InstrumentationRegistry.getInstrumentation().context,
|
||||
AnytypeDatabase::class.java
|
||||
).allowMainThreadQueries().build()
|
||||
|
||||
@After
|
||||
fun after() {
|
||||
database.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should return empty list if there are no last account in db`() {
|
||||
runBlocking {
|
||||
val accounts = database.accountDao().lastAccount()
|
||||
assertTrue { accounts.isEmpty() }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should return last account`() = runBlocking {
|
||||
|
||||
val firstAccount = AccountTable(
|
||||
id = MockDataFactory.randomString(),
|
||||
name = MockDataFactory.randomString(),
|
||||
timestamp = System.currentTimeMillis()
|
||||
)
|
||||
|
||||
delay(1)
|
||||
|
||||
val secondAccount = AccountTable(
|
||||
id = MockDataFactory.randomString(),
|
||||
name = MockDataFactory.randomString(),
|
||||
timestamp = System.currentTimeMillis()
|
||||
)
|
||||
|
||||
database.accountDao().insert(firstAccount)
|
||||
database.accountDao().insert(secondAccount)
|
||||
|
||||
val result = database.accountDao().lastAccount()
|
||||
|
||||
assertTrue { result.size == 1 }
|
||||
assertTrue { result.first() == secondAccount }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should return expected account when queried using account id`() = runBlocking {
|
||||
|
||||
val account = AccountTable(
|
||||
id = MockDataFactory.randomString(),
|
||||
name = MockDataFactory.randomString(),
|
||||
timestamp = System.currentTimeMillis()
|
||||
)
|
||||
|
||||
database.accountDao().insert(account)
|
||||
|
||||
val result = database.accountDao().getAccount(account.id)
|
||||
|
||||
assertEquals(account, result)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue