Skip to content

Commit

Permalink
Merge pull request #74 from ferPrieto/chore/Migrate-Mockito-Kotlin-To…
Browse files Browse the repository at this point in the history
…-Mockk

Chore/migrate mockito kotlin to mockk
  • Loading branch information
ferPrieto authored Feb 10, 2022
2 parents 7602db9 + 073f7e6 commit 0e344bb
Show file tree
Hide file tree
Showing 55 changed files with 439 additions and 336 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The purpose of this project is to consolidate some of the learned insights throu
* [Retrofit][5] Type-safe REST client for Android to consume RESTful web services.
* [Timber][6] Logger with a small API which provides utility on top of Android's normal Log class.
* [Espresso][7] Android UI Testing framework.
* [Mockito-Kotlin][8] test functions facilitation for Mockito (mocking framework for testing).
* [MockK][8] mocking framework for testing.
* [MockWebServer][9] A scriptable web server for testing HTTP clients, used for Instrumentation tests in this project.
* [Coil Compose][10] Image downloading and caching library supported by Jetpack Compose.
* [Lottie Compose][11] Library that provides that parses Adobe After Effects animations exported as json with Bodymovin and renders them natively on mobile.
Expand All @@ -45,7 +45,7 @@ The purpose of this project is to consolidate some of the learned insights throu
[5]: https://github.com/square/retrofit
[6]: https://github.com/JakeWharton/timber
[7]: https://developer.android.com/training/testing/espresso/
[8]: https://github.com/nhaarman/mockito-kotlin
[8]: https://mockk.io
[9]: https://github.com/square/okhttp/tree/master/mockwebserver
[10]: https://github.com/coil-kt/coil
[11]: https://airbnb.io/lottie/#/android-compose
Expand Down Expand Up @@ -96,7 +96,7 @@ These are the three options available (all of them maintained):

There are some highlights:
* Every layer in the architecture has been tested.
* Mockito has been used for mocking | stubbing.
* MockK has been used for mocking | stubbing.
* `Given | When | Then` code presentation order, in order to give a more structured style.
* Code Coverage (WORK IN PROGRESS).

Expand Down
14 changes: 7 additions & 7 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import prieto.fernando.dependencies.ProjectModules
import prieto.fernando.dependencies.Dependencies
import prieto.fernando.dependencies.ProjectModules
import prieto.fernando.dependencies.TestDependencies

plugins {
id("com.android.application")
kotlin("android")
kotlin("android.extensions")
id("prieto.fernando.android.plugin")
id("dagger.hilt.android.plugin")
id("org.jlleitschuh.gradle.ktlint") version "10.2.1"
}

androidPlugin{
androidPlugin {
buildType = prieto.fernando.android.plugin.BuildType.App
}

Expand All @@ -28,12 +28,13 @@ android {
}

composeOptions {
kotlinCompilerExtensionVersion = prieto.fernando.dependencies.Versions.compose
kotlinCompilerExtensionVersion = "1.0.5"
}

buildTypes {
getByName("debug") {
isDebuggable = true
isTestCoverageEnabled = true
buildConfigField("Integer", "PORT", "8080")
}
getByName("release") {
Expand All @@ -54,7 +55,7 @@ dependencies {
implementation(Dependencies.AndroidX.fragmentKtx)
implementation(Dependencies.AndroidX.lifecycleLivedataKtx)
implementation(Dependencies.AndroidX.Compose.viewModel)
annotationProcessor(Dependencies.AndroidX.lifecycleCompiler)
kapt(Dependencies.AndroidX.lifecycleCompiler)
implementation(Dependencies.AndroidX.archComponents)
implementation(Dependencies.AndroidX.browser)

Expand All @@ -68,7 +69,6 @@ dependencies {

implementation(Dependencies.Hilt.hiltAndroid)
implementation(Dependencies.Hilt.hiltAndroidCompiler)
implementation(Dependencies.Hilt.hiltViewModel)
implementation(Dependencies.Hilt.hiltCompiler)
implementation(Dependencies.Hilt.hiltNavigationCompose)

Expand Down Expand Up @@ -100,4 +100,4 @@ dependencies {
androidTestImplementation(TestDependencies.Hilt.androidTesting)
kaptAndroidTest(TestDependencies.Hilt.androidCompiler)
androidTestAnnotationProcessor(TestDependencies.Hilt.androidCompiler)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ import prieto.fernando.data_api.di.NetworkModule
)
class FakeNetworkModule : NetworkModule() {
override fun getBaseUrl() = "http://127.0.0.1:${BuildConfig.PORT}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.junit.runner.RunWith
import prieto.fernando.spacex.presentation.screens.base.BaseScreenTest
import prieto.fernando.spacex.webmock.SuccessDispatcher


@ExperimentalMaterialApi
@RunWith(AndroidJUnit4::class)
@HiltAndroidTest
Expand Down Expand Up @@ -47,4 +46,4 @@ class MainScreenKtTest : BaseScreenTest() {
.performClick()
composeTestRule.onNodeWithText("LAUNCHES", useUnmergedTree = true).assertIsDisplayed()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ open class BaseScreenTest {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ class DashboardScreenTest : BaseScreenTest() {
onNodeWithContentDescription("404 Animation").assertIsDisplayed()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class LaunchesScreenKtTest : BaseScreenTest() {
mockWebServer.dispatcher = SuccessDispatcher()
setMainContent()

launchesScreenRobot(composeTestRule) {
launchesScreenRobot(composeTestRule) {
clickOnLaunchesTab()
initialElementsShowed()
}
Expand Down Expand Up @@ -94,7 +94,8 @@ class LaunchesScreenKtTest : BaseScreenTest() {
onEventSent = {},
effectFlow = flow { emit(LaunchesContract.Effect.ClickableLink.None) },
onLinkClicked = { },
onClickableLinkRetrieved = { })
onClickableLinkRetrieved = { }
)
}
}

Expand All @@ -119,23 +120,29 @@ class LaunchesScreenKtTest : BaseScreenTest() {
state = LaunchesContract.State(
listOf(
LaunchUiModel(
"Mission1", "08-12-2021", true, "0", RocketUiModel(
"Mission1", "08-12-2021", true, "0",
RocketUiModel(
"Rocket1", "Rocket Type1"
), LinksUiModel("", "", "Youtube Link"), true
),
LinksUiModel("", "", "Youtube Link"), true
),
LaunchUiModel(
"Mission2", "09-12-2021", false, "0", RocketUiModel(
"Mission2", "09-12-2021", false, "0",
RocketUiModel(
"Rocket2", "Rocket Type2"
), LinksUiModel("", "WikiPedia Link", "Youtube Link"), false
),
LinksUiModel("", "WikiPedia Link", "Youtube Link"), false
)
), isLoading = false, isError = false
),
isLoading = false, isError = false
),
bottomSheetScaffoldState = bottomSheetScaffoldState,
coroutineScope = coroutineScope,
onEventSent = {},
effectFlow = flow { emit(LaunchesContract.Effect.ClickableLink.None) },
onLinkClicked = { },
onClickableLinkRetrieved = { })
onClickableLinkRetrieved = { }
)
}
}

Expand All @@ -145,4 +152,4 @@ class LaunchesScreenKtTest : BaseScreenTest() {
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package prieto.fernando.spacex.presentation.screens.launches

import androidx.compose.ui.test.*
import androidx.compose.ui.test.assertCountEquals
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.compose.ui.test.onAllNodesWithContentDescription
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.rules.ActivityScenarioRule
import kotlinx.coroutines.InternalCoroutinesApi
import prieto.fernando.spacex.presentation.EntryPointActivity

internal fun launchesScreenRobot(
Expand Down Expand Up @@ -93,8 +94,8 @@ internal open class LaunchesScreenRobot constructor(
listItemsShowed(0)
}

fun missionOneAndTwoShowed(){
fun missionOneAndTwoShowed() {
missionOneText.assertIsDisplayed()
missionTwoText.assertIsDisplayed()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ object AssetReaderUtil {
}
return builder.toString()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class ErrorDispatcher : Dispatcher() {
override fun dispatch(request: RecordedRequest): MockResponse {
return MockResponse().setResponseCode(404)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ class MockTestRunner : AndroidJUnitRunner() {
): Application {
return super.newApplication(cl, HiltTestApplication::class.java.name, context)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ class SuccessDispatcher(
errorResponse
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package prieto.fernando.spacex

import android.app.Application

open class BaseApplication : Application()
open class BaseApplication : Application()
1 change: 0 additions & 1 deletion app/src/main/java/prieto/fernando/spacex/SpaceXApp.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package prieto.fernando.spacex

import dagger.hilt.android.HiltAndroidApp
import android.app.Application

@HiltAndroidApp
class SpaceXApp : BaseApplication()
6 changes: 0 additions & 6 deletions app/src/main/java/prieto/fernando/spacex/di/AppModule.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
package prieto.fernando.spacex.di

import android.app.Application
import android.content.Context
import android.content.res.Resources
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent


@Module
@InstallIn(SingletonComponent::class)
open class AppModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import prieto.fernando.spacex.theme.SpaceXTheme
@AndroidEntryPoint
class EntryPointActivity : ComponentActivity() {

@InternalCoroutinesApi
@ExperimentalMaterialApi
@OptIn(InternalCoroutinesApi::class, ExperimentalMaterialApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ sealed class BottomNavigationScreens(
R.string.tab_title_launches,
R.drawable.ic_launches
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
Expand All @@ -34,15 +33,15 @@ import com.google.accompanist.systemuicontroller.rememberSystemUiController
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.InternalCoroutinesApi
import prieto.fernando.spacex.R
import prieto.fernando.spacex.presentation.navigation.BottomNavigationScreens
import prieto.fernando.spacex.presentation.screens.dashboard.DashboardScreen
import prieto.fernando.spacex.presentation.screens.launches.LaunchesContract
import prieto.fernando.spacex.presentation.screens.launches.LaunchesScreen
import prieto.fernando.spacex.presentation.navigation.BottomNavigationScreens
import prieto.fernando.spacex.presentation.vm.DashboardViewModel
import prieto.fernando.spacex.presentation.vm.LaunchesViewModel
import prieto.fernando.spacex.theme.Dark
import prieto.fernando.spacex.theme.Light
import prieto.fernando.spacex.theme.SpaceXTypography
import prieto.fernando.spacex.presentation.vm.DashboardViewModel
import prieto.fernando.spacex.presentation.vm.LaunchesViewModel

@InternalCoroutinesApi
@ExperimentalMaterialApi
Expand Down Expand Up @@ -167,16 +166,19 @@ private fun BottomSheet(
youTubeLinkState.value = effect.youTubeLink
wikipediaLinkState.value = effect.wikipedia
}
is LaunchesContract.Effect.ClickableLink.Youtube -> youTubeLinkState.value =
effect.youTubeLink
is LaunchesContract.Effect.ClickableLink.Wikipedia -> wikipediaLinkState.value =
effect.wikipedia
is LaunchesContract.Effect.ClickableLink.Youtube ->
youTubeLinkState.value =
effect.youTubeLink
is LaunchesContract.Effect.ClickableLink.Wikipedia ->
wikipediaLinkState.value =
effect.wikipedia
else -> {
youTubeLinkState.value = ""
wikipediaLinkState.value = ""
}
}
})
}
)
}
}

Expand Down Expand Up @@ -323,7 +325,6 @@ private fun getTabColour(selected: Boolean) =
else Dark.UnselectedTab
}


@Composable
private fun AnimatableIcon(
modifier: Modifier,
Expand Down Expand Up @@ -382,4 +383,4 @@ private fun AnimatableText(
private fun currentRoute(navController: NavHostController): String? {
val navBackStackEntry by navController.currentBackStackEntryAsState()
return navBackStackEntry?.destination?.route
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ fun ErrorAnimation(
modifier = modifier.semantics { contentDescription = "404 Animation" }
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ data class CompanyInfoUiModel(
val employees: String,
val launchSites: Int,
val valuation: Long
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class DashboardContract {
) : ViewState

object Effect : ViewSideEffect
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ fun DashboardScreen(
when {
state.isLoading -> {
LottieAnimation(
composition = loadingComposition,
composition = loadingComposition,
progress = loadingProgress,
modifier = Modifier.semantics { contentDescription= "Loading Animation" }
modifier = Modifier.semantics { contentDescription = "Loading Animation" }
)
}
state.isError -> {
Expand Down Expand Up @@ -92,4 +92,4 @@ private fun fillCompanyInfo(companyInfoUiModel: CompanyInfoUiModel): String =
companyInfoUiModel.employees,
companyInfoUiModel.launchSites,
companyInfoUiModel.valuation
)
)
Loading

0 comments on commit 0e344bb

Please sign in to comment.