TestHomeScreen1.java :  » App » pocketcampus » org » pocketcampus » test » Android Open Source

Android Open Source » App » pocketcampus 
pocketcampus » org » pocketcampus » test » TestHomeScreen1.java
package org.pocketcampus.test;

import org.pocketcampus.gui.mainscreen.HomeScreen1;
import org.pocketcampus.gui.preferences.Preferences;

import android.app.Activity;
import android.app.Instrumentation.ActivityMonitor;
import android.content.Context;
import android.test.ActivityInstrumentationTestCase2;
import android.test.ViewAsserts;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.view.KeyEvent;
import android.widget.ImageButton;

public class TestHomeScreen1 extends
    ActivityInstrumentationTestCase2<HomeScreen1> {

  private HomeScreen1 mActivity;
  private ImageButton mPrefButton;

  public TestHomeScreen1() {
    super("org.pocketcampus", HomeScreen1.class);
  }

  @Override
  protected void setUp() throws Exception {
    super.setUp();

    setActivityInitialTouchMode(false);

    mActivity = getActivity();

    mPrefButton = (ImageButton) mActivity
        .findViewById(org.pocketcampus.R.id.homescreen1_properties);
  }

  @MediumTest
  public void testPreconditions() {
    assertNotNull(mActivity);
  }

  @SmallTest
  public void testViewsVisible() {
    ViewAsserts.assertOnScreen(mPrefButton.getRootView(), mPrefButton);
  }

  // public void testUpwardsMotion() {
  // Display display = getActivity().getWindowManager().getDefaultDisplay();
  // int width = display.getWidth();
  // int height = display.getHeight();
  //
  // Display display = activity.getWindowManager().getDefaultDisplay();
  // int screenHeight = display.getHeight();
  // int screenWidth = display.getWidth();
  //
  // final float x = screenWidth / 2.0f;
  // final float fromY = screenHeight * 0.5f;
  // final float toY = screenHeight * 0.75f;
  //
  // drag(test, x, x, fromY, toY, 4);
  // ActivityInstrumentationTestCase2<Activity>InstrumentationTestCase itc =
  //
  // TouchUtils.dragViewToX(this, getActivity(), Gravity.LEFT, Gravity.RIGHT);
  // TouchUtils.drag(getInstrumentation(), (float) width / 2, (float) width /
  // 2,
  // (float) height, (float) height - 20, 1);
  // assertNotNull(getStartedActivityIntent());
  // }

  public void testPressingPrefsButton() {
    ActivityMonitor monitor = getInstrumentation().addMonitor(
        Preferences.class.getName(), null, false);

    mActivity.runOnUiThread(new Runnable() {

      @Override
      public void run() {
        mPrefButton.requestFocus();
      }
    });
    this.sendKeys(KeyEvent.KEYCODE_ENTER);

    Activity currentActivity = getInstrumentation().waitForMonitorWithTimeout(monitor, 5);

    assertTrue(getInstrumentation().checkMonitorHit(monitor, 1));
    currentActivity.finish();
//    System.out.println("Monitor hits " + monitor.getHits());
  }

  public void testLifeCycleCreate() {
    // At this point, onCreate() has been called, but nothing else
    // Complete the startup of the activity
    getInstrumentation().callActivityOnStart(mActivity);
    getInstrumentation().callActivityOnResume(mActivity);

    // On resume of the application
    assertNotNull(mActivity.getApplication());
    Context ctx = mActivity.getApplicationContext();
    assertNotNull(ctx);

    // At this point you could test for various configuration aspects, or
    // you could use a Mock Context to confirm that your activity has made
    // certain calls to the system and set itself up properly.

    getInstrumentation().callActivityOnPause(mActivity);
    // assertTrue(mActivity.get)
    // At this point you could confirm that the activity has paused
    // properly, as if it is no longer the topmost activity on screen.

    getInstrumentation().callActivityOnStop(mActivity);

    // At this point, you could confirm that the activity has shut itself
    // down appropriately,
    // or you could use a Mock Context to confirm that your activity has
    // released any system resources it should no longer be holding.

    // ActivityUnitTestCase.tearDown(), which is always automatically
    // called, will take care
    // of calling onDestroy().
  }
}

// public void testPressingRestaurantButton() {
// mActivity.runOnUiThread(new Runnable() {
// @Override
// public void run() {
// mRestaurantButton.requestFocus();
// }
// });
//
// if (mActivity.isInternetConnectionAvailable()) {
// this.sendKeys(KeyEvent.KEYCODE_ENTER);
// }
// }
//
// public void testPressingMapButton() {
// mMapButton = (ImageButton) mActivity
// .findViewById(org.pocketcampus.R.id.homescreen0_mapButton);
//
// mActivity.runOnUiThread(new Runnable() {
// @Override
// public void run() {
// mMapButton.requestFocus();
// }
// });
//
// if (mActivity.isInternetConnectionAvailable()) {
// this.sendKeys(KeyEvent.KEYCODE_ENTER);
// }
// }
// public void testPressingMetroButton() {
// mActivity.runOnUiThread(new Runnable() {
// @Override
// public void run() {
// mMetroButton.requestFocus();
// }
// });
// this.sendKeys(KeyEvent.KEYCODE_ENTER);
// assertTrue(mActivity.isInternetConnectionAvailable());
// }
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.