@@ -18,17 +18,9 @@ package com.android.example.paging.pagingwithnetwork.reddit.ui
18
18
19
19
import android.app.Application
20
20
import android.content.Intent
21
- import android.view.View
22
- import androidx.arch.core.executor.testing.CountingTaskExecutorRule
23
- import androidx.recyclerview.widget.RecyclerView
24
21
import androidx.test.annotation.UiThreadTest
25
22
import androidx.test.core.app.ActivityScenario
26
23
import androidx.test.core.app.ApplicationProvider
27
- import androidx.test.espresso.Espresso.onView
28
- import androidx.test.espresso.NoMatchingViewException
29
- import androidx.test.espresso.ViewAssertion
30
- import androidx.test.espresso.matcher.ViewMatchers.withId
31
- import com.android.example.paging.pagingwithnetwork.R
32
24
import com.android.example.paging.pagingwithnetwork.reddit.DefaultServiceLocator
33
25
import com.android.example.paging.pagingwithnetwork.reddit.ServiceLocator
34
26
import com.android.example.paging.pagingwithnetwork.reddit.api.RedditApi
@@ -38,10 +30,8 @@ import com.android.example.paging.pagingwithnetwork.reddit.repository.RedditPost
38
30
import com.android.example.paging.pagingwithnetwork.reddit.ui.SubRedditViewModel.Companion.DEFAULT_SUBREDDIT
39
31
import com.android.example.paging.pagingwithnetwork.repository.FakeRedditApi
40
32
import com.android.example.paging.pagingwithnetwork.repository.PostFactory
41
- import org.hamcrest.CoreMatchers.`is`
42
- import org.hamcrest.MatcherAssert.assertThat
33
+ import org.junit.Assert.assertEquals
43
34
import org.junit.Before
44
- import org.junit.Rule
45
35
import org.junit.Test
46
36
import org.junit.runner.RunWith
47
37
import org.junit.runners.Parameterized
@@ -57,9 +47,6 @@ class RedditActivityTest(private val type: RedditPostRepository.Type) {
57
47
fun params () = arrayOf(IN_MEMORY_BY_ITEM , IN_MEMORY_BY_PAGE )
58
48
}
59
49
60
- @get:Rule
61
- var testRule = CountingTaskExecutorRule ()
62
-
63
50
private val postFactory = PostFactory ()
64
51
65
52
@Before
@@ -80,7 +67,7 @@ class RedditActivityTest(private val type: RedditPostRepository.Type) {
80
67
@Test
81
68
@UiThreadTest
82
69
fun showSomeResults () {
83
- ActivityScenario .launch<RedditActivity >(
70
+ val scenario = ActivityScenario .launch<RedditActivity >(
84
71
RedditActivity .intentFor(
85
72
context = ApplicationProvider .getApplicationContext(),
86
73
type = type
@@ -89,17 +76,9 @@ class RedditActivityTest(private val type: RedditPostRepository.Type) {
89
76
}
90
77
)
91
78
92
- onView(withId(R .id.list)).check(RecyclerViewItemCountAssertion (3 ))
93
- }
94
-
95
- class RecyclerViewItemCountAssertion (private val expectedCount : Int ) : ViewAssertion {
96
- override fun check (view : View , noViewFoundException : NoMatchingViewException ? ) {
97
- if (noViewFoundException != null ) {
98
- throw noViewFoundException
99
- }
100
- val recyclerView = view as RecyclerView
101
- val adapter = recyclerView.adapter
102
- assertThat(adapter!! .itemCount, `is `(expectedCount))
79
+ scenario.onActivity { activity ->
80
+ val recyclerView = activity.binding.list
81
+ assertEquals(3 , recyclerView.adapter?.itemCount)
103
82
}
104
83
}
105
84
}
0 commit comments