1 package net.pterodactylus.sone.test
3 import net.pterodactylus.sone.utils.Pagination
4 import org.hamcrest.Description
5 import org.hamcrest.TypeSafeDiagnosingMatcher
8 * Hamcrest matcher for [Pagination]s.
10 class PaginationMatcher(private val page: Int? = null, private val pages: Int? = null):
11 TypeSafeDiagnosingMatcher<Pagination<*>>() {
13 override fun matchesSafely(pagination: Pagination<*>, mismatchDescription: Description): Boolean {
15 if (pagination.page != page) {
16 mismatchDescription.appendText("page is ").appendValue(pagination.page)
21 if (pagination.pageCount != pages) {
22 mismatchDescription.appendText("total pages is ").appendValue(pagination.pageCount)
29 override fun describeTo(description: Description) {
31 description.appendText("is on page ").appendValue(page)
33 description.appendText(" of ").appendValue(pages)
36 description.appendText("has ").appendValue(pages).appendText(" pages")
40 fun isOnPage(page: Int) = PaginationMatcher(page = page, pages = pages)
41 fun hasPages(pages: Int) = PaginationMatcher(page = page, pages = pages)
45 fun isOnPage(page: Int) = PaginationMatcher(page = page)
46 fun hasPages(pages: Int) = PaginationMatcher(pages = pages)