This repository has been archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added helper functions for testing coroutines. Fixed problem with del…
…ay in coroutines.
- Loading branch information
Showing
4 changed files
with
93 additions
and
41 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
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,51 @@ | ||
package dk.nodes.arch | ||
|
||
import androidx.lifecycle.Lifecycle | ||
import dk.nodes.arch.presentation.base.BasePresenterImpl | ||
import dk.nodes.arch.presentation.base.BaseView | ||
import dk.nodes.arch.presentation.base.runBlockingTest | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import kotlinx.coroutines.InternalCoroutinesApi | ||
import kotlinx.coroutines.delay | ||
import org.junit.Test | ||
|
||
class CoroutineTest { | ||
|
||
private class View: BaseView { | ||
fun showData() { | ||
println("Showing data") | ||
} | ||
} | ||
|
||
private class Presenter: BasePresenterImpl<View>() { | ||
|
||
fun loadData() { | ||
println("loadData start in thread ${Thread.currentThread().name}") | ||
launchOnUI { | ||
println("loadData before delay in thread ${Thread.currentThread().name}") | ||
delay(1000) | ||
println("loadData after delay in thread ${Thread.currentThread().name}") | ||
view { showData() } | ||
println("loadData after view in thread ${Thread.currentThread().name}") | ||
} | ||
println("loadData end in thread ${Thread.currentThread().name}") | ||
} | ||
} | ||
|
||
@InternalCoroutinesApi | ||
@Test | ||
fun `Test run blocking with context launches coroutine on same thread`() { | ||
val viewMock = mockk<View>(relaxed = true) | ||
val lifecycleMock = mockk<Lifecycle>(relaxed = true) | ||
val presenter = Presenter() | ||
|
||
presenter.onViewCreated(viewMock, lifecycleMock) | ||
|
||
runBlockingTest(presenter) { | ||
presenter.loadData() | ||
} | ||
|
||
verify { viewMock.showData() } | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.