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
8 changes: 7 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import ytemplate.android.jacoco.addExclusion

@Suppress("DSL_SCOPE_VIOLATION") // scope violation issue: work around suggested from: https://github.com/gradle/gradle/issues/22797
plugins {
id("ytemplate.android.application")
id("ytemplate.android.application.jacoco")
id("ytemplate.android.application.compose")
id("ytemplate.android.hilt")
}

private val excludedFiles = mutableSetOf(
"**/ytemplate/android/MainActivity.*",
"**/ytemplate/android/YTemplate.*"
)
addExclusion(excludedFiles)
android {
namespace = "ytemplate.android"
defaultConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ class HiltConventionPlugin : Plugin<Project> {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LibraryConventionPlugin : Plugin<Project> {
apply(libs.findPlugin("android.library").get().get().pluginId)
apply(libs.findPlugin("kotlin.android").get().get().pluginId)
apply(libs.findPlugin("kotlin.serialization").get().get().pluginId)

apply(libs.findPlugin("ksp").get().get().pluginId)
}

extensions.configure<LibraryExtension> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ytemplate.android.jacoco.jacoco
*
* @constructor Create empty Library jacoco convention plugin
*/
@Suppress("UNCHECKED_CAST")
class ProjectJacocoConventionPlugin : Plugin<Project> {
private val project_level_limits = mutableMapOf(
"instruction" to 0.0,
Expand All @@ -36,7 +37,6 @@ class ProjectJacocoConventionPlugin : Plugin<Project> {

override fun apply(target: Project) {
with(target) {
val libs = extensions.getByType<VersionCatalogsExtension>().named("versionCatalogLibs")
with(pluginManager) {
apply("jacoco")
}
Expand Down
4 changes: 2 additions & 2 deletions build-logic/src/main/java/ytemplate/android/jacoco/Jacoco.kt
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private fun Project.addTestCoverageTask(
}
}
}

@Suppress("UNCHECKED_CAST")
fun Project.jacocoTestReport(taskName: String) {
val reportDir = jacoco.reportsDirectory.asFile.get()
val report = file("$reportDir/$taskName/${taskName}.xml")
Expand All @@ -235,7 +235,7 @@ private fun Project.addTestCoverageTask(
}

}

@Suppress("UNCHECKED_CAST")
fun File.extractTestCoverage(): Map<String, Double> {
val xmlReader = XmlSlurper().apply {
setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
Expand Down
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

buildscript {
repositories {
mavenCentral()
Expand All @@ -14,6 +16,7 @@ buildscript {
plugins {
alias(versionCatalogLibs.plugins.kotlin.serialization) apply false
alias(versionCatalogLibs.plugins.hilt) apply false
alias(versionCatalogLibs.plugins.ksp) apply false
alias(versionCatalogLibs.plugins.sonar)
alias(versionCatalogLibs.plugins.dokka)
alias(versionCatalogLibs.plugins.ktlint)
Expand Down
2 changes: 1 addition & 1 deletion core/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import ytemplate.android.jacoco.setModuleTestCoverageLimits

plugins {
id("ytemplate.android.library")
id("ytemplate.android.library.jacoco")
id("ytemplate.android.hilt")
id("ytemplate.android.library.jacoco")
}

private val excludedFiles = mutableSetOf(
Expand Down
9 changes: 8 additions & 1 deletion core/database/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,20 @@ setModuleTestCoverageLimits(limits)

android {
namespace = "ytemplate.android.database"
defaultConfig {
javaCompileOptions {
annotationProcessorOptions {
arguments["room.schemaLocation"] = "$projectDir/schemas"
}
}
}
}

dependencies {
implementation(project(mapOf("path" to ":core:common")))
// Room
implementation(versionCatalogLibs.bundles.room)
kapt(versionCatalogLibs.room.compiler)
ksp(versionCatalogLibs.room.compiler)
implementation(versionCatalogLibs.androidx.test.monitor)
androidTestImplementation(versionCatalogLibs.bundles.test)
androidTestImplementation(versionCatalogLibs.coroutine.test)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"formatVersion": 1,
"database": {
"version": 5,
"identityHash": "7c4a48bedc91be7b793fa52a2e0676ef",
"entities": [
{
"tableName": "PostTable",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `userId` INTEGER NOT NULL, `title` TEXT NOT NULL, `body` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "userId",
"columnName": "userId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "body",
"columnName": "body",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '7c4a48bedc91be7b793fa52a2e0676ef')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ytemplate.android.core.database.model.PostEntity
*
* @constructor Create empty App data base
*/
@Database(entities = [PostEntity::class], version = DATABASE_VERSION)
@Database(entities = [PostEntity::class], version = DATABASE_VERSION, exportSchema = false)
abstract class AppDataBase : RoomDatabase() {
/**
* My model dao
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class FakePostRepository(val fakePostDao: FakePostDao = FakePostDao(), val fakeP
private val _feed = MutableSharedFlow<List<Post>>()
override val feed: SharedFlow<List<Post>> = _feed.asSharedFlow()

override suspend fun add(post: Post) {
fakePostDao.insert(post.map())
override suspend fun add(postItem: Post) {
fakePostDao.insert(postItem.map())
emitData()
}

Expand All @@ -40,7 +40,7 @@ class FakePostRepository(val fakePostDao: FakePostDao = FakePostDao(), val fakeP
AppResult.Success(remoteData.toPostList())
} else {
emitData()
AppResult.Error((remoteData as AppResult.Error).exception)
AppResult.Error()
}
} catch (ex: Exception) {
emitData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ fun PostListScreen(viewModel: MyPostViewModel = hiltViewModel()) {
AppLoadingIndicator()
}
is MyPostModelUiState.Error -> {
StickyErrorMessageCard((dataState as MyPostModelUiState.Error).throwable.localizedMessage)
(dataState as MyPostModelUiState.Error).throwable.localizedMessage?.let {
StickyErrorMessageCard(
it
)
}
}
}
}
Expand Down Expand Up @@ -144,7 +148,7 @@ fun PreviewPostListScreen() {
modifier = Modifier
.fillMaxWidth()
.padding(dimensions.paddingLarge)
) { newPost ->
) { _ ->
}
SimplePostList(
listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ import kotlin.time.Duration.Companion.milliseconds
*/
@OptIn(ExperimentalCoroutinesApi::class)
class MyPostViewModelTest {
private lateinit var repository: FakePostRepository

/**
* Set up
*
*/
@Before
fun setUp() {
Dispatchers.setMain(UnconfinedTestDispatcher())
repository = FakePostRepository()
}

/**
Expand All @@ -41,6 +38,7 @@ class MyPostViewModelTest {
*/
@Test
fun `test initial data is empty state`() = runTest {
var repository = FakePostRepository()
val viewModel = MyPostViewModel(repository)
viewModel.uiState.test {
val firstDataState = awaitItem()
Expand All @@ -56,6 +54,7 @@ class MyPostViewModelTest {
*/
@Test
fun `test get data success state`() = runTest {
var repository = FakePostRepository()
repository.fakePostApi.remotePostDataMock.setExpectSuccess()
repository.fakePostApi.remotePostDataMock.setExpectedResponse(PlaceHolderData.DUMMY_DATA_GET_ALL_POST)
val viewModel = MyPostViewModel(repository)
Expand All @@ -76,6 +75,7 @@ class MyPostViewModelTest {
*/
@Test
fun `test delete single data state`() = runTest {
var repository = FakePostRepository()
repository.fakePostApi.remotePostDataMock.setExpectSuccess()
repository.fakePostApi.remotePostDataMock.setExpectedResponse(PlaceHolderData.DUMMY_DATA_GET_ALL_POST)
val viewModel = MyPostViewModel(repository)
Expand All @@ -100,6 +100,7 @@ class MyPostViewModelTest {
*/
@Test
fun `test add single data state`() = runTest {
var repository = FakePostRepository()
repository.fakePostApi.remotePostDataMock.setExpectSuccess()
repository.fakePostApi.remotePostDataMock.setExpectedResponse(PlaceHolderData.DUMMY_DATA_GET_ALL_POST)
val viewModel = MyPostViewModel(repository)
Expand All @@ -122,6 +123,7 @@ class MyPostViewModelTest {
*/
@Test
fun `test errorState`() = runTest {
var repository = FakePostRepository()
repository.fakePostApi.remotePostDataMock.setExpectFailure()
repository.fakePostApi.remotePostDataMock.setExpectedResponse(null)
val viewModel = MyPostViewModel(repository)
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ kotlinxCoroutines = "1.6.4"
kotlinxSerializationJson = "1.4.1"

#gradle
androidGradlePlugin = "7.4.1"
androidGradlePlugin = "7.4.2"

#androidx
androidxComposeBom = "2022.12.00"
Expand Down Expand Up @@ -41,7 +41,7 @@ compose_ui_testing = "1.4.0-beta01"
core_ktx = "1.9.0"

#ksp
ksp = "1.7.21-1.0.8"
ksp = "1.8.10-1.0.9"

#coroutine
coroutine = "1.6.4"
Expand Down
7 changes: 7 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
],
"baseBranches": ["multi_module"]
}