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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/tests/background/junit3/src/helpers/AndroidSyncTestCase.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,52 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +package org.mozilla.gecko.background.helpers;
     1.8 +
     1.9 +import junit.framework.AssertionFailedError;
    1.10 +
    1.11 +import org.mozilla.gecko.background.testhelpers.WaitHelper;
    1.12 +
    1.13 +import android.app.Activity;
    1.14 +import android.content.Context;
    1.15 +import android.test.ActivityInstrumentationTestCase2;
    1.16 +
    1.17 +/**
    1.18 + * AndroidSyncTestCase provides helper methods for testing.
    1.19 + */
    1.20 +public class AndroidSyncTestCase extends ActivityInstrumentationTestCase2<Activity> {
    1.21 +  protected static String LOG_TAG = "AndroidSyncTestCase";
    1.22 +
    1.23 +  public AndroidSyncTestCase() {
    1.24 +    super(Activity.class);
    1.25 +    WaitHelper.resetTestWaiter();
    1.26 +  }
    1.27 +
    1.28 +  public Context getApplicationContext() {
    1.29 +    return this.getInstrumentation().getTargetContext().getApplicationContext();
    1.30 +  }
    1.31 +
    1.32 +  public static void performWait(Runnable runnable) {
    1.33 +    try {
    1.34 +      WaitHelper.getTestWaiter().performWait(runnable);
    1.35 +    } catch (WaitHelper.InnerError e) {
    1.36 +      AssertionFailedError inner = new AssertionFailedError("Caught error in performWait");
    1.37 +      inner.initCause(e.innerError);
    1.38 +      throw inner;
    1.39 +    }
    1.40 +  }
    1.41 +
    1.42 +  public static void performNotify() {
    1.43 +    WaitHelper.getTestWaiter().performNotify();
    1.44 +  }
    1.45 +
    1.46 +  public static void performNotify(Throwable e) {
    1.47 +    WaitHelper.getTestWaiter().performNotify(e);
    1.48 +  }
    1.49 +
    1.50 +  public static void performNotify(String reason, Throwable e) {
    1.51 +    AssertionFailedError er = new AssertionFailedError(reason + ": " + e.getMessage());
    1.52 +    er.initCause(e);
    1.53 +    WaitHelper.getTestWaiter().performNotify(er);
    1.54 +  }
    1.55 +}

mercurial