Skip to content

Commit

Permalink
Add core module tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexymumo committed Mar 23, 2024
1 parent 934e2bf commit 4e6f2db
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2024 News-App
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alexmumo.database.db

import android.content.Context
import androidx.room.Room
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.alexmumo.database.dao.ArticleDao
import com.alexmumo.database.dao.BookMarkDao
import com.alexmumo.database.dao.RemoteKeyDao
import com.alexmumo.database.entity.ArticleEntity
import com.alexmumo.database.entity.SourceEntity
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class NewsDatabaseTest {

private lateinit var articleDao: ArticleDao
private lateinit var bookMarkDao: BookMarkDao
private lateinit var remoteKeyDao: RemoteKeyDao
private lateinit var newsDatabase: NewsDatabase

@Before
fun setUpDatabase() {
val context = ApplicationProvider.getApplicationContext<Context>()
newsDatabase = Room.inMemoryDatabaseBuilder(
context,
NewsDatabase::class.java
).build()
}

@OptIn(ExperimentalCoroutinesApi::class)
@Test
fun saveArticles_returns_a_listOf_articles() = runTest {
}

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

companion object {
private val article = ArticleEntity(author = null, content = null, description = null, publishedAt = null, title = null, SourceEntity(id = null, name = ""), url = "", urlToImage = null)
val articles = listOf(article)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2024 News-App
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alexmumo.datastore

class NewsPreferenceTest
2 changes: 2 additions & 0 deletions core/database/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ dependencies {

implementation(libs.android.core)
implementation(libs.android.appcompat)
implementation(libs.junit.androidx.ktx)
testImplementation(libs.junit)
androidTestImplementation(libs.expresso.core)
androidTestImplementation(libs.truth)
androidTestImplementation(libs.junit)
testImplementation(libs.truth)
androidTestImplementation(libs.core.testing)
implementation(libs.core.ktx)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2024 News-App
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alexmumo.database.db

import android.content.Context
import androidx.room.Room
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.alexmumo.database.dao.ArticleDao
import com.alexmumo.database.dao.BookMarkDao
import com.alexmumo.database.dao.RemoteKeyDao
import com.alexmumo.database.entity.ArticleEntity
import com.alexmumo.database.entity.SourceEntity
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class NewsDatabaseTest {

private lateinit var articleDao: ArticleDao
private lateinit var bookMarkDao: BookMarkDao
private lateinit var remoteKeyDao: RemoteKeyDao
private lateinit var newsDatabase: NewsDatabase

@Before
fun setUpDatabase() {
val context = ApplicationProvider.getApplicationContext<Context>()
newsDatabase = Room.inMemoryDatabaseBuilder(
context,
NewsDatabase::class.java
).build()
}

@OptIn(ExperimentalCoroutinesApi::class)
@Test
fun saveArticles_returns_a_listOf_articles() = runTest {
}

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

companion object {
private val article = ArticleEntity(author = null, content = null, description = null, publishedAt = null, title = null, SourceEntity(id = null, name = ""), url = "", urlToImage = null)
val articles = listOf(article)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2024 News-App
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alexmumo.datastore

class NewsPreferenceTest

0 comments on commit 4e6f2db

Please sign in to comment.