This file contains hidden or 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
class TestContextProvider : CoroutineContextProvider() { | |
override val Main: CoroutineContext = Dispatchers.Unconfined | |
override val IO: CoroutineContext = Dispatchers.Unconfined | |
} |
This file contains hidden or 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
class TestCoroutineRule : TestRule { | |
private val testCoroutineDispatcher = TestCoroutineDispatcher() | |
private val testCoroutineScope = TestCoroutineScope(testCoroutineDispatcher) | |
override fun apply(base: Statement, description: Description?) = object : Statement() { | |
@Throws(Throwable::class) | |
override fun evaluate() { | |
Dispatchers.setMain(testCoroutineDispatcher) | |
base.evaluate() |
This file contains hidden or 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
class MyViewModelTest { | |
@get:Rule | |
val instantExecutorRule = InstantTaskExecutorRule() | |
@get:Rule | |
val testCoroutineRule = TestCoroutineRule() | |
private lateinit var myViewModel: MyViewModel | |
@Mock |
This file contains hidden or 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
open class CoroutineContextProvider @Inject constructor() { | |
open val Main: CoroutineContext by lazy { Dispatchers.Main } | |
open val IO: CoroutineContext by lazy { Dispatchers.IO } | |
} |
This file contains hidden or 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
class MyViewModel( | |
private val getDataUseCase: GetDataUseCase, | |
private val contextProvider: CoroutineContextProvider | |
) : ViewModel() { | |
private val handler = CoroutineExceptionHandler { _, exception -> | |
stateLiveData.value = MyViewState.Error(exception) | |
} | |
private val stateLiveData = MutableLiveData<MyViewState>() |
This file contains hidden or 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
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion" | |
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion" | |
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion" |
This file contains hidden or 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
Widget build(BuildContext context) { | |
return Column(children: [ | |
Text(mainText), | |
...buildMainElements(), | |
if (page != pages.last) | |
FlatButton(child: Text('Next')), | |
for (var section in sections) | |
HeadingAction(section.heading), | |
]); | |
} |
This file contains hidden or 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
mixin Wings { | |
String speed = "fast" | |
void fly() { | |
print('Flying $speed') | |
} | |
} |
This file contains hidden or 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
class Bird extends Animal with Wings |
This file contains hidden or 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
class Bird(wings: Flying) : Animal, Flying by wings |