Skip to content

Commit

Permalink
Added few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gideonrotich committed Jan 17, 2024
1 parent af8ea39 commit bcff42d
Show file tree
Hide file tree
Showing 30 changed files with 195 additions and 623 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ dependencies {
implementation(project(":compose-ui"))
implementation(project(":feature:home"))
implementation(project(":feature:favourite"))
implementation(project(":sync:work"))

implementation("io.github.raamcosta.compose-destinations:animations-core:1.7.32-beta")
ksp("io.github.raamcosta.compose-destinations:ksp:1.7.32-beta")
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/com/swayy/wezacare/HarryPotterApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
package com.swayy.wezacare

import android.app.Application
import com.swayy.work.initializers.Sync
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class HarryPotterApp : Application() {
override fun onCreate() {
super.onCreate()
// Initialize Sync; the system responsible for keeping data in the app up to date.
Sync.initialize(context = this)
}
}
1 change: 0 additions & 1 deletion app/src/main/java/com/swayy/wezacare/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class MainActivity : ComponentActivity() {
)
}
}

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion base-module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ dependencies {
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.38.1'
testImplementation 'junit:junit:4.13.2'
testImplementation "androidx.test:runner:1.4.0"
testImplementation "com.google.truth:truth:1.1.3"
testImplementation "com.google.truth:truth:1.1.5"
testImplementation 'androidx.test:core-ktx:1.4.0'
testImplementation "org.robolectric:robolectric:4.5.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
package com.swayy.core_database

import android.content.Context
import androidx.room.PrimaryKey
import androidx.room.Room
import androidx.test.core.app.ApplicationProvider
import androidx.test.runner.AndroidJUnit4
import com.google.common.truth.Truth
import com.google.gson.Gson
import com.swayy.core_database.converters.Converters
import com.swayy.core_database.dao.CharacterDao
import com.swayy.core_database.model.CharacterEntity
import com.swayy.core_network.model.harrypotter.Wand
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class CharactersDatabaseTest {

private lateinit var dao: CharacterDao
private lateinit var db: CharactersDatabase

@Before
fun createDb() {
val context = ApplicationProvider.getApplicationContext<Context>()
val converters = Converters(Gson())

db = Room.inMemoryDatabaseBuilder(
context, CharactersDatabase::class.java
)
.addTypeConverter(converters)
.allowMainThreadQueries()
.build()
dao = db.characterDao
}

@Test
fun `test adding empty list followed by valid data`() = runTest {
dao.insertCharacters(emptyList())

Truth.assertThat(dao.getCharacters().isEmpty())

dao.insertCharacters(
listOf(
CharacterEntity(
actor = "Gideon",
alive = true,
alternate_actors = emptyList(),
alternate_names = emptyList(),
ancestry = "Chumo",
dateOfBirth = "2002",
eyeColour = "white",
gender = "male",
hairColour = "black",
hogwartsStaff = false,
hogwartsStudent = true,
house = "harryp",
id = "1",
image = "",
name = "gede",
patronus = "Alliance",
species = "animalia",
wand = Wand("", 0.0, ""),
wizard = true,
yearOfBirth = 2001
)
)
)

Truth.assertThat(dao.getCharacters().size).isEqualTo(1)
}

@Test
fun `adding fav to db returns valid data on query`() = runTest {
val entity = CharacterEntity(
actor = "Gideon",
alive = true,
alternate_actors = emptyList(),
alternate_names = emptyList(),
ancestry = "Chumo",
dateOfBirth = "2002",
eyeColour = "white",
gender = "male",
hairColour = "black",
hogwartsStaff = false,
hogwartsStudent = true,
house = "harryp",
id = "1",
image = "",
name = "gede",
patronus = "Alliance",
species = "animalia",
wand = Wand("", 0.0, ""),
wizard = true,
yearOfBirth = 2001
)

dao.insertCharacters(listOf(entity) )

Truth.assertThat(dao.getCharacters()).containsExactly(entity)
}

@Test
fun `deleting fav to db updates properly`() = runTest {
val entity = CharacterEntity(
actor = "Gideon",
alive = true,
alternate_actors = emptyList(),
alternate_names = emptyList(),
ancestry = "Chumo",
dateOfBirth = "2002",
eyeColour = "white",
gender = "male",
hairColour = "black",
hogwartsStaff = false,
hogwartsStudent = true,
house = "harryp",
id = "1",
image = "",
name = "gede",
patronus = "Alliance",
species = "animalia",
wand = Wand("", 0.0, ""),
wizard = true,
yearOfBirth = 2001
)

val entityTwo = CharacterEntity(
actor = "Brian",
alive = true,
alternate_actors = emptyList(),
alternate_names = emptyList(),
ancestry = "Chumo",
dateOfBirth = "2002",
eyeColour = "white",
gender = "male",
hairColour = "black",
hogwartsStaff = false,
hogwartsStudent = true,
house = "harryp",
id = "2",
image = "",
name = "gede",
patronus = "Alliance",
species = "animalia",
wand = Wand("", 0.0, ""),
wizard = true,
yearOfBirth = 2001
)

dao.insertCharacters(listOf(entity,entityTwo) )

Truth.assertThat(dao.getCharacters().size).isEqualTo(2)

dao.deleteCharacters(listOf(entity.id) )
Truth.assertThat(dao.getCharacters().size).isEqualTo(1)

dao.deleteCharacters(listOf(entityTwo.id) )
Truth.assertThat(dao.getCharacters()).isEmpty()
}

}
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ include ':core-database'
include ':core-network'
include ':feature'
include ':feature:home'
include ':sync'
include ':sync:work'
include ':feature:favourite'
1 change: 0 additions & 1 deletion sync/work/.gitignore

This file was deleted.

69 changes: 0 additions & 69 deletions sync/work/build.gradle.kts

This file was deleted.

Empty file removed sync/work/consumer-rules.pro
Empty file.
21 changes: 0 additions & 21 deletions sync/work/proguard-rules.pro

This file was deleted.

Loading

0 comments on commit bcff42d

Please sign in to comment.