Created
June 23, 2018 07:38
-
-
Save shanmugasanthosh7/ddbbe8015b3b3cf98071d7321376edf2 to your computer and use it in GitHub Desktop.
Simple Unit test with RxJava and Mockito
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
@RunWith(MockitoJUnitRunner::class) | |
class MainPresenterImplTest { | |
@Mock | |
private lateinit var apiService: ApiService | |
@Mock | |
private lateinit var mainView: MainView | |
private lateinit var testScheduler: TestScheduler | |
private lateinit var mainPresenter: MainPresenter | |
@Mock | |
private lateinit var posts: ArrayList<Post> | |
@Before | |
fun setUp() { | |
testScheduler = TestScheduler() | |
val testSchedulerProvider = TestSchedulerProvider(testScheduler) | |
mainPresenter = MainPresenterImpl(mainView, apiService, testSchedulerProvider) | |
} | |
@Test | |
fun loadViewTest() { | |
doReturn(Observable.just(posts)) | |
.`when`(apiService) | |
.getPosts() | |
mainPresenter.onLoadView() | |
testScheduler.triggerActions() | |
verify(mainView).loadView(posts) | |
} | |
@After | |
fun tearDown() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment