From 7998b2a262aa809f9879d51e6edc55ddadcf2699 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 14 Jun 2015 18:06:57 +0200 Subject: instrument: add helper method for snackbar checking --- .../keychain/actions/CustomMatchers.java | 27 ++++++++++++++++++++++ .../keychain/ui/util/Notify.java | 23 ++++++------------ 2 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomMatchers.java (limited to 'OpenKeychain') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomMatchers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomMatchers.java new file mode 100644 index 000000000..29e875b95 --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomMatchers.java @@ -0,0 +1,27 @@ +package org.sufficientlysecure.keychain.actions; + + +import android.support.annotation.ColorRes; +import android.support.test.espresso.matcher.BoundedMatcher; +import android.view.View; + +import com.nispok.snackbar.Snackbar; +import org.hamcrest.Description; +import org.hamcrest.Matcher; + +public abstract class CustomMatchers { + + public static Matcher withSnackbarLineColor(@ColorRes final int colorRes) { + return new BoundedMatcher(Snackbar.class) { + public void describeTo(Description description) { + description.appendText("with color resource id: " + colorRes); + } + + @Override + public boolean matchesSafely(Snackbar snackbar) { + return snackbar.getResources().getColor(colorRes) == snackbar.getLineColor(); + } + }; + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java index 8c554dbde..7dfd56430 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java @@ -38,25 +38,16 @@ import org.sufficientlysecure.keychain.util.FabContainer; public class Notify { public static enum Style { - OK, WARN, ERROR; + OK (R.color.android_green_light), WARN(R.color.android_orange_light), ERROR(R.color.android_red_light); - public void applyToBar(Snackbar bar) { + public final int mLineColor; - switch (this) { - case OK: - // bar.actionColorResource(R.color.android_green_light); - bar.lineColorResource(R.color.android_green_light); - break; - case WARN: - // bar.textColorResource(R.color.android_orange_light); - bar.lineColorResource(R.color.android_orange_light); - break; - case ERROR: - // bar.textColorResource(R.color.android_red_light); - bar.lineColorResource(R.color.android_red_light); - break; - } + Style(int color) { + mLineColor = color; + } + public void applyToBar(Snackbar bar) { + bar.lineColorResource(mLineColor); } } -- cgit v1.2.3