Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d52647fa authored by Amit Kumar's avatar Amit Kumar 💻
Browse files

Add Content Provider backed by Room Database

parent 7566d467
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="GradleMigrationSettings" migrationVersion="1" />
  <component name="GradleSettings">
    <option name="linkedExternalProjectsSettings">
      <GradleProjectSettings>
+7 −0
Original line number Diff line number Diff line
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 29
@@ -28,8 +29,14 @@ dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'

    def room_version = "2.2.5"
    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"

    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:core:1.2.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

+0 −24
Original line number Diff line number Diff line
package foundation.e.pwaplayer

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
 * Instrumented test, which will execute on an Android device.
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
    @Test
    fun useAppContext() {
        // Context of the app under test.
        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
        assertEquals("foundation.e.pwaplayer", appContext.packageName)
    }
}
 No newline at end of file
+40 −0
Original line number Diff line number Diff line
package foundation.e.pwaplayer.database

import androidx.room.Room
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import org.hamcrest.Matchers.`is`
import org.junit.After
import org.junit.Assert.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@SmallTest
class PwaTest {

    private lateinit var database: PwaDatabase

    @Before
    fun createDatabase() {
        database = Room.inMemoryDatabaseBuilder(
            ApplicationProvider.getApplicationContext(),
            PwaDatabase::class.java
        ).build()
    }

    @After
    fun closeDatabase() {
        database.close()
    }

    @Test
    fun insertAndCount() {
        assertThat(database.pwaDao().count(), `is`(0))
        val pwa = Pwa(shortcutId = "test-shortcut", url = "https://e.foundation")
        database.pwaDao().insert(pwa)
        assertThat(database.pwaDao().count(), `is`(1))
    }
}
 No newline at end of file
+42 −0
Original line number Diff line number Diff line
package foundation.e.pwaplayer.provider

import android.content.ContentResolver
import android.content.Context
import android.database.Cursor
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import org.hamcrest.CoreMatchers.notNullValue
import org.hamcrest.Matchers.`is`
import org.junit.Assert.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith


@RunWith(AndroidJUnit4::class)
@SmallTest
class PwaProviderTest {
    private lateinit var contentResolver: ContentResolver

    @Before
    fun setUp() {
        val context: Context = ApplicationProvider.getApplicationContext()
        //SampleDatabase.switchToInMemory(context)
        contentResolver = context.contentResolver
    }

    @Test
    fun cheese_initiallyEmpty() {
        val cursor: Cursor? = contentResolver.query(
            URI_PWA,
            arrayOf<String>("url"),
            null,
            null,
            null
        )
        assertThat(cursor, notNullValue())
        assertThat(cursor!!.count, `is`(0))
        cursor!!.close()
    }
}
 No newline at end of file
Loading