forked from cobeisfresh/CleanArchitecture-Android-Showcase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/routing
# Conflicts: # app/build.gradle # app/src/main/java/com/cobeisfresh/template/di/PresentationModule.kt # app/src/main/java/com/cobeisfresh/template/ui/weather/presentation/WeatherViewModel.kt # data/build.gradle # domain/build.gradle
- Loading branch information
Showing
12 changed files
with
78 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/cobeisfresh/template/common/coroutine/CoroutineContextProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.cobeisfresh.template.common.coroutine | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
open class CoroutineContextProvider { | ||
open val main: CoroutineContext by lazy { Dispatchers.Main } | ||
open val io: CoroutineContext by lazy { Dispatchers.IO } | ||
open val default: CoroutineContext by lazy { Dispatchers.Default } | ||
} | ||
|
||
class TestCoroutineContextProvider : CoroutineContextProvider() { | ||
override val main: CoroutineContext = Dispatchers.Unconfined | ||
override val io: CoroutineContext = Dispatchers.Unconfined | ||
override val default: CoroutineContext = Dispatchers.Unconfined | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.cobeisfresh | ||
|
||
const val TEMP = 20.0 | ||
const val HUMIDITY = 20 | ||
const val PRESSURE = 1013.30 | ||
const val OSIJEK_CITY_NAME = "Osijek" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,37 @@ | ||
package com.cobeisfresh | ||
|
||
import org.junit.runner.RunWith | ||
import org.mockito.junit.MockitoJUnitRunner | ||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule | ||
import com.cobeisfresh.template.common.coroutine.TestCoroutineContextProvider | ||
import com.cobeisfresh.template.ui.weather.base.ViewState | ||
import com.cobeisfresh.template.ui.weather.presentation.WeatherViewModel | ||
import com.example.domain.interaction.weather.GetWeatherUseCase | ||
import com.example.domain.model.Success | ||
import com.example.domain.model.WeatherInfo | ||
import com.nhaarman.mockitokotlin2.mock | ||
import com.nhaarman.mockitokotlin2.whenever | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TestRule | ||
import org.mockito.junit.MockitoJUnit | ||
import org.mockito.junit.MockitoRule | ||
|
||
@RunWith(MockitoJUnitRunner::class) | ||
class WeatherViewModelTest { | ||
|
||
|
||
private val getWeather: GetWeatherUseCase = mock() | ||
private val coroutineContext = TestCoroutineContextProvider() | ||
private val weatherViewModel by lazy { WeatherViewModel(getWeather, coroutineContext) } | ||
|
||
@get:Rule | ||
val rule: TestRule = InstantTaskExecutorRule() | ||
@get:Rule | ||
val mockitoRule: MockitoRule = MockitoJUnit.rule() | ||
|
||
@Test | ||
fun `test getWeather sets liveData value when success`() = runBlocking { | ||
whenever(getWeather(OSIJEK_CITY_NAME)).thenReturn(Success(WeatherInfo(TEMP, HUMIDITY, PRESSURE))) | ||
weatherViewModel.getWeatherForLocation(OSIJEK_CITY_NAME) | ||
assertEquals(ViewState.Status.SUCCESS, weatherViewModel.weatherLiveData.value?.status) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters