Created
February 23, 2016 15:32
-
-
Save elevenetc/8038fe98bc603b91b288 to your computer and use it in GitHub Desktop.
Revisions
-
elevenetc created this gist
Feb 23, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ public class ExtraAssertions { public static ViewAssertion isVisible() { return (view, noView) -> assertThat(view, new VisibilityMatcher(View.VISIBLE)); } public static ViewAssertion isGone() { return (view, noView) -> assertThat(view, new VisibilityMatcher(View.GONE)); } public static ViewAssertion isInvisible() { return (view, noView) -> assertThat(view, new VisibilityMatcher(View.INVISIBLE)); } private static class VisibilityMatcher extends BaseMatcher<View> { private int visibility; public VisibilityMatcher(int visibility) { this.visibility = visibility; } @Override public void describeTo(Description description) { String visibilityName; if (visibility == View.GONE) visibilityName = "GONE"; else if (visibility == View.VISIBLE) visibilityName = "VISIBLE"; else visibilityName = "INVISIBLE"; description.appendText("View visibility must has equals " + visibilityName); } @Override public boolean matches(Object o) { if (o == null) { if (visibility == View.GONE || visibility == View.INVISIBLE) return true; else if (visibility == View.VISIBLE) return false; } if (!(o instanceof View)) throw new IllegalArgumentException("Object must be instance of View. Object is instance of " + o); return ((View) o).getVisibility() == visibility; } } }