Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #106 from aafanasev/master
Browse files Browse the repository at this point in the history
Make hasSize() error message a little bit more descriptive
  • Loading branch information
VerachadW authored Jun 14, 2018
2 parents f399c4d + 8c05095 commit 3279d93
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions kakao/src/main/kotlin/com/agoda/kakao/Matchers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class ProgressMatcher(private val value: Int) : BoundedMatcher<View, ProgressBar

/**
* Matcher of value rating of given matcher
*
*
* @param value of rating that matched the view which is RatingBar
*/
class RatingBarMatcher(private val value: Float) : BoundedMatcher<View, RatingBar>(RatingBar::class.java) {
Expand All @@ -190,30 +190,48 @@ class RatingBarMatcher(private val value: Float) : BoundedMatcher<View, RatingBa
}

/**
* Matches RecyclerView with count of childs
* Matches RecyclerView with count of children
*
* @param size of childs count in RecyclerView
* @param size of children count in RecyclerView
*/
class RecyclerViewAdapterSizeMatcher(private val size: Int) : BoundedMatcher<View, RecyclerView>(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<View, ListView>(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)
}
}

Expand Down

0 comments on commit 3279d93

Please sign in to comment.