Skip to content

Commit

Permalink
Move all withText(String) to withCompatText(String)
Browse files Browse the repository at this point in the history
  • Loading branch information
alorma committed Mar 11, 2021
1 parent 293c7ad commit d46995b
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.view.View
import com.schibsted.spain.barista.internal.assertAnyView
import com.schibsted.spain.barista.internal.failurehandler.RethrowingFailureHandler
import com.schibsted.spain.barista.internal.matcher.BooleanMatcher
import com.schibsted.spain.barista.internal.matcher.withCompatText
import com.schibsted.spain.barista.internal.util.resourceMatcher
import org.hamcrest.Matcher
import org.junit.Assert.fail
Expand Down Expand Up @@ -42,7 +43,7 @@ object BaristaAssertions {
*/
@JvmStatic
inline fun <reified T : View> assertAny(text: String, assertionDescription: String? = null, noinline block: (T) -> Boolean) {
assertAny(ViewMatchers.withText(text), assertionDescription, block)
assertAny(withCompatText(text), assertionDescription, block)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.schibsted.spain.barista.assertion

import androidx.test.espresso.matcher.ViewMatchers.isChecked
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.schibsted.spain.barista.internal.matcher.withCompatText
import com.schibsted.spain.barista.internal.assertAny
import com.schibsted.spain.barista.internal.util.resourceMatcher
import org.hamcrest.Matchers.not
Expand All @@ -15,7 +15,7 @@ object BaristaCheckedAssertions {

@JvmStatic
fun assertChecked(text: String) {
withText(text).assertAny(isChecked())
withCompatText(text).assertAny(isChecked())
}

@JvmStatic
Expand All @@ -25,6 +25,6 @@ object BaristaCheckedAssertions {

@JvmStatic
fun assertUnchecked(text: String) {
withText(text).assertAny(not(isChecked()))
withCompatText(text).assertAny(not(isChecked()))
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.schibsted.spain.barista.assertion

import androidx.test.espresso.matcher.ViewMatchers.isClickable
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.schibsted.spain.barista.internal.matcher.withCompatText
import com.schibsted.spain.barista.internal.assertAny
import com.schibsted.spain.barista.internal.util.resourceMatcher
import org.hamcrest.Matchers.not
Expand All @@ -15,7 +15,7 @@ object BaristaClickableAssertions {

@JvmStatic
fun assertClickable(text: String) {
withText(text).assertAny(isClickable())
withCompatText(text).assertAny(isClickable())
}

@JvmStatic
Expand All @@ -25,6 +25,6 @@ object BaristaClickableAssertions {

@JvmStatic
fun assertNotClickable(text: String) {
withText(text).assertAny(not(isClickable()))
withCompatText(text).assertAny(not(isClickable()))
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.schibsted.spain.barista.assertion

import androidx.test.espresso.matcher.ViewMatchers.isEnabled
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.schibsted.spain.barista.internal.matcher.withCompatText
import com.schibsted.spain.barista.internal.assertAny
import com.schibsted.spain.barista.internal.util.resourceMatcher
import org.hamcrest.Matchers.not
Expand All @@ -15,7 +15,7 @@ object BaristaEnabledAssertions {

@JvmStatic
fun assertEnabled(text: String) {
withText(text).assertAny(isEnabled())
withCompatText(text).assertAny(isEnabled())
}

@JvmStatic
Expand All @@ -25,6 +25,6 @@ object BaristaEnabledAssertions {

@JvmStatic
fun assertDisabled(text: String) {
withText(text).assertAny(not(isEnabled()))
withCompatText(text).assertAny(not(isEnabled()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.schibsted.spain.barista.assertion

import androidx.annotation.IdRes
import androidx.test.espresso.matcher.ViewMatchers.hasFocus
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.schibsted.spain.barista.internal.matcher.withCompatText
import com.schibsted.spain.barista.internal.assertAny
import com.schibsted.spain.barista.internal.util.resourceMatcher
import org.hamcrest.Matchers.not
Expand All @@ -21,11 +21,11 @@ object BaristaFocusedAssertions {

@JvmStatic
fun assertFocused(text: String) {
withText(text).assertAny(hasFocus())
withCompatText(text).assertAny(hasFocus())
}

@JvmStatic
fun assertNotFocused(text: String) {
withText(text).assertAny(not(hasFocus()))
withCompatText(text).assertAny(not(hasFocus()))
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package com.schibsted.spain.barista.assertion

import android.view.View
import android.widget.ListView
import androidx.annotation.IdRes
import androidx.annotation.StringRes
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso
import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.ViewAssertion
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.recyclerview.widget.RecyclerView
import android.view.View
import android.widget.ListView
import com.schibsted.spain.barista.interaction.BaristaListInteractions
import com.schibsted.spain.barista.interaction.BaristaListInteractions.findListViewMatcher
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.matcher.ListViewNotEmptyAssertion
import com.schibsted.spain.barista.internal.matcher.ListViewItemCountAssertion
import com.schibsted.spain.barista.internal.matcher.RecyclerViewNotEmptyAssertion
import com.schibsted.spain.barista.internal.matcher.ListViewNotEmptyAssertion
import com.schibsted.spain.barista.internal.matcher.RecyclerViewItemCountAssertion
import com.schibsted.spain.barista.internal.matcher.RecyclerViewNotEmptyAssertion
import com.schibsted.spain.barista.internal.matcher.withCompatText
import org.hamcrest.CoreMatchers
import org.hamcrest.Description
import org.hamcrest.Matcher
Expand Down Expand Up @@ -80,8 +81,8 @@ object BaristaListAssertions {
targetViewId = targetViewId,
viewAssertion = ViewAssertions.matches(
CoreMatchers.anyOf(
ViewMatchers.withChild(ViewMatchers.withText(text)),
ViewMatchers.withText(text)
ViewMatchers.withChild(withCompatText(text)),
withCompatText(text)
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object BaristaVisibilityAssertions {

@JvmStatic
fun assertDisplayed(text: String) {
withText(text).assertAny(isDisplayed())
withCompatText(text).assertAny(isDisplayed())
}

@JvmStatic
Expand All @@ -55,7 +55,7 @@ object BaristaVisibilityAssertions {

@JvmStatic
fun assertNotExist(text: String) {
onView(withText(text)).check(doesNotExist())
onView(withCompatText(text)).check(doesNotExist())
}

@JvmStatic
Expand All @@ -65,7 +65,7 @@ object BaristaVisibilityAssertions {

@JvmStatic
fun assertNotDisplayed(text: String) {
withText(text).assertAny(not(isDisplayed()))
withCompatText(text).assertAny(not(isDisplayed()))
}

@JvmStatic
Expand All @@ -75,7 +75,7 @@ object BaristaVisibilityAssertions {

@JvmStatic
fun assertNotDisplayed(@IdRes viewId: Int, text: String) {
viewId.resourceMatcher().assertAny(not(allOf(isDisplayed(), withText(text))))
viewId.resourceMatcher().assertAny(not(allOf(isDisplayed(), withCompatText(text))))
}

@JvmStatic
Expand All @@ -85,7 +85,7 @@ object BaristaVisibilityAssertions {

@JvmStatic
fun assertContains(text: String) {
withText(containsString(text)).assertAny(isDisplayed())
withCompatText(containsString(text)).assertAny(isDisplayed())
}

@JvmStatic
Expand All @@ -96,7 +96,7 @@ object BaristaVisibilityAssertions {

@JvmStatic
fun assertContains(@IdRes viewId: Int, text: String) {
viewId.resourceMatcher().assertAny(withText(containsString(text)))
viewId.resourceMatcher().assertAny(withCompatText(containsString(text)))
}

@JvmStatic
Expand All @@ -107,7 +107,7 @@ object BaristaVisibilityAssertions {

@JvmStatic
fun assertNotContains(text: String) {
onView(withText(containsString(text))).check(doesNotExist())
onView(withCompatText(containsString(text))).check(doesNotExist())
}

@JvmStatic
Expand All @@ -118,7 +118,7 @@ object BaristaVisibilityAssertions {

@JvmStatic
fun assertNotContains(@IdRes resId: Int, text: String) {
onView(allOf(withId(resId), withText(containsString(text)))).check(doesNotExist())
onView(allOf(withId(resId), withCompatText(containsString(text)))).check(doesNotExist())
}

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.schibsted.spain.barista.interaction
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.longClick
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.schibsted.spain.barista.internal.matcher.withCompatText
import com.schibsted.spain.barista.internal.performAction
import com.schibsted.spain.barista.internal.util.resourceMatcher

Expand All @@ -21,7 +21,7 @@ object BaristaClickInteractions {

@JvmStatic
fun clickOn(text: String) {
withText(text).performAction(click())
withCompatText(text).performAction(click())
}

@JvmStatic
Expand All @@ -31,6 +31,6 @@ object BaristaClickInteractions {

@JvmStatic
fun longClickOn(text: String) {
withText(text).performAction(longClick())
withCompatText(text).performAction(longClick())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.matcher.RootMatchers.isPlatformPopup
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.schibsted.spain.barista.internal.matcher.withCompatText
import android.view.View
import androidx.test.core.app.ApplicationProvider
import com.schibsted.spain.barista.internal.failurehandler.SpyFailureHandler
Expand Down Expand Up @@ -40,7 +40,7 @@ object BaristaMenuClickInteractions {
fun clickMenu(text: String) {
val spyFailureHandler = SpyFailureHandler()
try {
clickDisplayedView(withText(text), spyFailureHandler)
clickDisplayedView(withCompatText(text), spyFailureHandler)
} catch (noMatchingViewException: NoMatchingViewException) {
try {
clickViewWithDescription(text, spyFailureHandler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.annotation.IdRes
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.schibsted.spain.barista.internal.matcher.withCompatText
import com.schibsted.spain.barista.internal.matcher.HelperMatchers.withParentId
import com.schibsted.spain.barista.internal.performAction
import org.hamcrest.Matchers.allOf
Expand All @@ -19,7 +19,7 @@ object BaristaRadioButtonInteractions {

@JvmStatic
fun clickRadioButtonItem(@IdRes radioGroupId: Int, text: String) {
allOf(withParentId(radioGroupId), withText(text))
allOf(withParentId(radioGroupId), withCompatText(text))
.performAction(click())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.schibsted.spain.barista.interaction
import android.view.View
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.PerformException
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.schibsted.spain.barista.internal.matcher.withCompatText
import com.schibsted.spain.barista.internal.failurehandler.SpyFailureHandler
import com.schibsted.spain.barista.internal.failurehandler.description
import com.schibsted.spain.barista.internal.util.resourceMatcher
Expand Down Expand Up @@ -32,7 +32,7 @@ object BaristaScrollInteractions {

@JvmStatic
fun scrollTo(text: String) {
scrollWithMultipleAttempts(withText(text), failAtEnd = true)
scrollWithMultipleAttempts(withCompatText(text), failAtEnd = true)
}

@JvmStatic
Expand All @@ -47,7 +47,7 @@ object BaristaScrollInteractions {

@JvmStatic
fun safelyScrollTo(text: String) {
scrollWithMultipleAttempts(withText(text), failAtEnd = false)
scrollWithMultipleAttempts(withCompatText(text), failAtEnd = false)
}

private fun scrollWithMultipleAttempts(matcher: Matcher<View>, failAtEnd: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.View
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import com.schibsted.spain.barista.internal.matcher.withCompatText
import org.hamcrest.Matcher

class BaristaResourceTypeException(message: String) : RuntimeException(message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.schibsted.spain.barista.internal.viewaction;

import android.view.View;
import android.widget.TextView;
import androidx.annotation.IdRes;
import androidx.test.espresso.PerformException;
import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.util.HumanReadables;
import android.view.View;
import android.widget.TextView;
import com.schibsted.spain.barista.internal.failurehandler.HelperFunctionsKt;
import com.schibsted.spain.barista.internal.util.ViewTreeAnalyzer;
import org.hamcrest.Matcher;

import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static com.schibsted.spain.barista.internal.matcher.TextMatcherKt.withCompatText;
import static org.hamcrest.Matchers.allOf;

public class ClickChildAction {
Expand Down Expand Up @@ -50,11 +50,11 @@ public void perform(UiController uiController, View view) {
};
}

public static ViewAction clickChildWithText(final String text) {
public static ViewAction clickChildwithCompatText(final String text) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return allOf(isDisplayed(), hasDescendant(withText(text)));
return allOf(isDisplayed(), hasDescendant(withCompatText(text)));
}

@Override
Expand Down

0 comments on commit d46995b

Please sign in to comment.