-
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.
Merge pull request #69 from AppDevNext/RecyclerViewItemCountAssertion
RecyclerViewItemCountAssertion
- Loading branch information
Showing
3 changed files
with
86 additions
and
11 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
moka/src/main/java/com/moka/lib/assertions/RecyclerViewItemCountAssertion.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,27 @@ | ||
package com.moka.lib.assertions | ||
|
||
import android.view.View | ||
import androidx.recyclerview.widget.RecyclerView | ||
import androidx.test.espresso.NoMatchingViewException | ||
import androidx.test.espresso.ViewAssertion | ||
import org.hamcrest.MatcherAssert | ||
import org.hamcrest.Matchers | ||
|
||
class RecyclerViewItemCountAssertion(private val expectedCount: Int, private val operator: MatchOperator) : ViewAssertion { | ||
|
||
override fun check(view: View?, noViewFoundException: NoMatchingViewException?) { | ||
noViewFoundException?.let { | ||
throw it | ||
} | ||
val recyclerView = view as RecyclerView | ||
val adapter = recyclerView.adapter | ||
when (operator) { | ||
MatchOperator.IS -> MatcherAssert.assertThat(adapter!!.itemCount, Matchers.`is`(expectedCount)) | ||
MatchOperator.LESS -> MatcherAssert.assertThat(adapter!!.itemCount, Matchers.lessThan(expectedCount)) | ||
MatchOperator.LESS_EQUAL -> MatcherAssert.assertThat(adapter!!.itemCount, Matchers.lessThanOrEqualTo(expectedCount)) | ||
MatchOperator.GREATER -> MatcherAssert.assertThat(adapter!!.itemCount, Matchers.greaterThan(expectedCount)) | ||
MatchOperator.GREATER_EQUAL -> MatcherAssert.assertThat(adapter!!.itemCount, Matchers.greaterThanOrEqualTo(expectedCount)) | ||
} | ||
|
||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
sample/src/androidTest/java/com/sample/app/RecyclerViewWaitTest.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,46 @@ | ||
package com.sample.app | ||
|
||
import androidx.test.ext.junit.rules.ActivityScenarioRule | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.moka.lib.assertions.MatchOperator | ||
import com.moka.lib.assertions.WaitingAssertion | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class RecyclerViewWaitTest { | ||
|
||
@get:Rule | ||
var activityScenarioRule = ActivityScenarioRule(MainActivity::class.java) | ||
|
||
@Test | ||
fun testRecyclerViewWaitItemCount() { | ||
WaitingAssertion.assertAdapterMinimumItemsCount(R.id.recyclerTest, 2, 500) | ||
} | ||
|
||
@Test | ||
fun testRecyclerViewWaitItemCountEqual() { | ||
WaitingAssertion.assertRecyclerAdapterItemsCount(R.id.recyclerTest, 3, MatchOperator.IS, 500) | ||
} | ||
|
||
@Test | ||
fun testRecyclerViewWaitItemCountLessEqual() { | ||
WaitingAssertion.assertRecyclerAdapterItemsCount(R.id.recyclerTest, 3, MatchOperator.LESS_EQUAL, 500) | ||
} | ||
|
||
@Test | ||
fun testRecyclerViewWaitItemCountLess() { | ||
WaitingAssertion.assertRecyclerAdapterItemsCount(R.id.recyclerTest, 4, MatchOperator.LESS, 500) | ||
} | ||
|
||
@Test | ||
fun testRecyclerViewWaitItemCountGreater() { | ||
WaitingAssertion.assertRecyclerAdapterItemsCount(R.id.recyclerTest, 2, MatchOperator.GREATER, 500) | ||
} | ||
|
||
@Test | ||
fun testRecyclerViewWaitItemCountGreaterEqual() { | ||
WaitingAssertion.assertRecyclerAdapterItemsCount(R.id.recyclerTest, 3, MatchOperator.GREATER_EQUAL, 500) | ||
} | ||
} |