mobile/android/tests/background/junit3/src/helpers/AndroidSyncTestCase.java

branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
equal deleted inserted replaced
-1:000000000000 0:693109e55d78
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 package org.mozilla.gecko.background.helpers;
5
6 import junit.framework.AssertionFailedError;
7
8 import org.mozilla.gecko.background.testhelpers.WaitHelper;
9
10 import android.app.Activity;
11 import android.content.Context;
12 import android.test.ActivityInstrumentationTestCase2;
13
14 /**
15 * AndroidSyncTestCase provides helper methods for testing.
16 */
17 public class AndroidSyncTestCase extends ActivityInstrumentationTestCase2<Activity> {
18 protected static String LOG_TAG = "AndroidSyncTestCase";
19
20 public AndroidSyncTestCase() {
21 super(Activity.class);
22 WaitHelper.resetTestWaiter();
23 }
24
25 public Context getApplicationContext() {
26 return this.getInstrumentation().getTargetContext().getApplicationContext();
27 }
28
29 public static void performWait(Runnable runnable) {
30 try {
31 WaitHelper.getTestWaiter().performWait(runnable);
32 } catch (WaitHelper.InnerError e) {
33 AssertionFailedError inner = new AssertionFailedError("Caught error in performWait");
34 inner.initCause(e.innerError);
35 throw inner;
36 }
37 }
38
39 public static void performNotify() {
40 WaitHelper.getTestWaiter().performNotify();
41 }
42
43 public static void performNotify(Throwable e) {
44 WaitHelper.getTestWaiter().performNotify(e);
45 }
46
47 public static void performNotify(String reason, Throwable e) {
48 AssertionFailedError er = new AssertionFailedError(reason + ": " + e.getMessage());
49 er.initCause(e);
50 WaitHelper.getTestWaiter().performNotify(er);
51 }
52 }

mercurial