Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Commit

Permalink
Fix assertListItemCount not throwing error when failed bug (AdevintaS…
Browse files Browse the repository at this point in the history
  • Loading branch information
vykintas authored and Sloy committed Dec 18, 2018
1 parent ced9a8d commit 8d92261
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.schibsted.spain.barista.interaction.BaristaListInteractions.findListV
import com.schibsted.spain.barista.interaction.BaristaListInteractions.findRecyclerMatcher
import com.schibsted.spain.barista.interaction.BaristaListInteractions.scrollListToPosition
import com.schibsted.spain.barista.internal.failurehandler.SpyFailureHandler
import com.schibsted.spain.barista.internal.failurehandler.withFailureHandler
import com.schibsted.spain.barista.internal.matcher.ListViewItemCountAssertion
import com.schibsted.spain.barista.internal.matcher.RecyclerViewItemCountAssertion
import org.hamcrest.CoreMatchers
Expand All @@ -29,10 +30,10 @@ object BaristaListAssertions {
val listViewMatcher = findListViewMatcher(listId)

try {
Espresso.onView(recyclerMatcher).check(RecyclerViewItemCountAssertion(expectedItemCount))
Espresso.onView(recyclerMatcher).withFailureHandler(spyFailureHandler).check(RecyclerViewItemCountAssertion(expectedItemCount))
} catch (noRecyclerMatching: NoMatchingViewException) {
try {
Espresso.onView(listViewMatcher).check(ListViewItemCountAssertion(expectedItemCount))
Espresso.onView(listViewMatcher).withFailureHandler(spyFailureHandler).check(ListViewItemCountAssertion(expectedItemCount))
} catch (listViewError: Throwable) {
spyFailureHandler.resendLastError("Item count mismatch on ListView. Expected $expectedItemCount items in the list.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import com.schibsted.spain.barista.assertion.BaristaListAssertions.assertDisplayedAtPosition
import com.schibsted.spain.barista.assertion.BaristaListAssertions.assertListItemCount
import com.schibsted.spain.barista.internal.failurehandler.BaristaException
import junit.framework.AssertionFailedError
import org.junit.Rule
import org.junit.Test
Expand All @@ -24,6 +25,13 @@ class ListViewAssertionTest {
assertListItemCount(R.id.listview, expectedListLength)
}

@Test(expected = BaristaException::class)
fun shouldFailWhenNumberOfEntriesInListViewDoesNotMatchExpected() {
openSimpleListActivity()
val expectedListLength = ListsActivity.FRUITS.size
assertListItemCount(R.id.listview, expectedListLength + 1)
}

@Test
fun shouldFindItemInListViewWithoutIdInSimpleList() {
openSimpleListActivity()
Expand Down

0 comments on commit 8d92261

Please sign in to comment.