From 8c0509574924ca5bbbc42cbaded597a8ead6d847 Mon Sep 17 00:00:00 2001 From: jokuskay Date: Thu, 14 Jun 2018 00:19:49 +0700 Subject: [PATCH] add actual count of items of RecyclerView / ListView in error message --- .../main/kotlin/com/agoda/kakao/Matchers.kt | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/kakao/src/main/kotlin/com/agoda/kakao/Matchers.kt b/kakao/src/main/kotlin/com/agoda/kakao/Matchers.kt index 76c4b47a..fa29cebf 100644 --- a/kakao/src/main/kotlin/com/agoda/kakao/Matchers.kt +++ b/kakao/src/main/kotlin/com/agoda/kakao/Matchers.kt @@ -178,7 +178,7 @@ class ProgressMatcher(private val value: Int) : BoundedMatcher(RatingBar::class.java) { @@ -190,30 +190,48 @@ class RatingBarMatcher(private val value: Float) : BoundedMatcher(RecyclerView::class.java) { - override fun matchesSafely(view: RecyclerView?) = view?.adapter?.let { - it.itemCount == size } ?: false + + private var itemCount: Int = 0 + + override fun matchesSafely(view: RecyclerView) = run { + itemCount = view.adapter?.itemCount ?: 0 + itemCount == size + } override fun describeTo(description: Description) { - description.appendText("recycle view size is: $size") + description + .appendText("RecyclerView with ") + .appendValue(size) + .appendText(" item(s), but got with ") + .appendValue(itemCount) } } /** - * Matches ListView with count of childs + * Matches ListView with count of children * - * @param size of childs count in ListView + * @param size of children count in ListView */ class ListViewViewAdapterSizeMatcher(private val size: Int) : BoundedMatcher(ListView::class.java) { - override fun matchesSafely(view: ListView?) = view?.adapter?.let { - it.count == size } ?: false + + private var itemCount: Int = 0 + + override fun matchesSafely(view: ListView) = run { + itemCount = view.adapter?.count ?: 0 + itemCount == size + } override fun describeTo(description: Description) { - description.appendText("recycle view size is: $size") + description + .appendText("ListView with ") + .appendValue(size) + .appendText(" item(s), but got with ") + .appendValue(itemCount) } }