aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-06-15 04:05:07 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2015-06-17 18:52:59 +0200
commit71ea52119898f2e9552b542b2bcc40ad430ae8a3 (patch)
tree3320bfb28b11782feca7e4065e7fd65f0e3bab3c /OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java
parentb8305d43dcae87b441e48eb8f47e471e0b0c2781 (diff)
downloadopen-keychain-71ea52119898f2e9552b542b2bcc40ad430ae8a3.tar.gz
open-keychain-71ea52119898f2e9552b542b2bcc40ad430ae8a3.tar.bz2
open-keychain-71ea52119898f2e9552b542b2bcc40ad430ae8a3.zip
clean up helper code, add withKeyItemId matcher for KeyListAdapter
Diffstat (limited to 'OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java')
-rw-r--r--OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java
new file mode 100644
index 000000000..0adc6b264
--- /dev/null
+++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java
@@ -0,0 +1,55 @@
+package org.sufficientlysecure.keychain;
+
+
+import android.content.Context;
+import android.support.annotation.StringRes;
+
+import org.hamcrest.CoreMatchers;
+import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
+import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow;
+import org.sufficientlysecure.keychain.provider.ProviderHelper;
+import org.sufficientlysecure.keychain.ui.util.Notify.Style;
+import org.sufficientlysecure.keychain.util.ProgressScaler;
+
+import static android.support.test.InstrumentationRegistry.getInstrumentation;
+import static android.support.test.espresso.Espresso.onView;
+import static android.support.test.espresso.assertion.ViewAssertions.matches;
+import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
+import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
+import static android.support.test.espresso.matcher.ViewMatchers.withText;
+import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withSnackbarLineColor;
+
+
+public class TestHelpers {
+
+
+ public static void checkSnackbar(Style style, @StringRes Integer text) {
+
+ onView(withClassName(CoreMatchers.endsWith("Snackbar")))
+ .check(matches(withSnackbarLineColor(style.mLineColor)));
+
+ if (text != null) {
+ onView(withClassName(CoreMatchers.endsWith("Snackbar")))
+ .check(matches(hasDescendant(withText(text))));
+ }
+
+ }
+
+
+ static void importKeysFromResource(Context context, String name) throws Exception {
+ IteratorWithIOThrow<UncachedKeyRing> stream = UncachedKeyRing.fromStream(
+ getInstrumentation().getContext().getAssets().open(name));
+
+ ProviderHelper helper = new ProviderHelper(context);
+ while(stream.hasNext()) {
+ UncachedKeyRing ring = stream.next();
+ if (ring.isSecret()) {
+ helper.saveSecretKeyRing(ring, new ProgressScaler());
+ } else {
+ helper.saveSecretKeyRing(ring, new ProgressScaler());
+ }
+ }
+
+ }
+
+}