Android Open Source - watchme Searchable Activity Test






From Project

Back to project page watchme.

License

The source code is released under:

Copyright (c) 2012 Johan Brook, Robin Andersson, Lisa Stenberg, Mattias Henriksson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documen...

If you think the Android project watchme listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package se.chalmers.watchmetest.activity;
//from  w w w .j  a va  2 s .co m
import se.chalmers.watchme.R;
import se.chalmers.watchme.activity.MainActivity;
import se.chalmers.watchme.database.DatabaseHelper;
import se.chalmers.watchmetest.Constants;
import android.test.ActivityInstrumentationTestCase2;
import android.view.KeyEvent;

import com.jayway.android.robotium.solo.Solo;

/**
 * Class that tests functionality implemented in the SearchableActivity class.
 * Tests are performed with methods from the robotium api.
 * 
 * @author mattiashenriksson
 * 
 */
public class SearchableActivityTest extends
    ActivityInstrumentationTestCase2<MainActivity> {

  Solo solo;
  DatabaseHelper dbh;

  public SearchableActivityTest() {
    super(MainActivity.class);
  }

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    solo = new Solo(getInstrumentation(), getActivity());
    dbh = new DatabaseHelper(getActivity());
  }

  @Override
  public void tearDown() throws Exception {
    // Finish all activities that have been opened during test execution.
    solo.finishOpenedActivities();

    // Clear list of movies stored in database
    dbh.onUpgrade(dbh.getWritableDatabase(), 1, 1);
  }

  /**
   * Test if you can search for movies and if the application will display the correct result if you do.
   */
  public void testSearch() {
    // Clear list of movies stored in database
    dbh.onUpgrade(dbh.getWritableDatabase(), 1, 1);
      
    solo.waitForActivity("MainActivity");

    // Add two movies with different titles
    char movieFirstCharacter = 'A';
    for (int i = 0; i < 2; i++) {
      solo.clickOnActionBarItem(R.id.menu_main_add_movie);
      solo.waitForActivity("AddMovieActivity");
      solo.enterText(Constants.TITLE_FIELD, movieFirstCharacter
          + "_MOVIE");
      solo.clickOnActionBarItem(R.id.menu_add_movie);
      solo.waitForActivity("MainActivity");

      movieFirstCharacter++;
    }
    
    // Search for one of the movies
    solo.clickOnActionBarItem(R.id.menu_search_button);
    solo.sleep(2000);
    solo.enterText(0, "A_");
    solo.sendKey(KeyEvent.KEYCODE_ENTER);
      
    boolean isSearchableActivityViewed = solo.waitForActivity("SearchableActivity");
    assertTrue(isSearchableActivityViewed);
      
    boolean isAMovieViewed = solo.searchText("A_MOVIE");
    boolean isBMovieViewed = solo.searchText("B_MOVIE");
    
    // Check that the correct result is displayed
    assertTrue(isAMovieViewed);
    assertFalse(isBMovieViewed);
      
  }
}




Java Source Code List

se.chalmers.watchme.activity.AddMovieActivity.java
se.chalmers.watchme.activity.AutoCompleteAdapter.java
se.chalmers.watchme.activity.MainActivity.java
se.chalmers.watchme.activity.MovieDetailsActivity.java
se.chalmers.watchme.activity.SearchableActivity.java
se.chalmers.watchme.activity.TabsAdapter.java
se.chalmers.watchme.activity.TagMovieListActivity.java
se.chalmers.watchme.database.DatabaseAdapter.java
se.chalmers.watchme.database.DatabaseHelper.java
se.chalmers.watchme.database.GenericCursorLoader.java
se.chalmers.watchme.database.HasTagTable.java
se.chalmers.watchme.database.ICursorHelper.java
se.chalmers.watchme.database.MovieAlreadyExistsException.java
se.chalmers.watchme.database.MoviesTable.java
se.chalmers.watchme.database.TagsTable.java
se.chalmers.watchme.database.WatchMeContentProvider.java
se.chalmers.watchme.model.Movie.java
se.chalmers.watchme.model.Tag.java
se.chalmers.watchme.net.HttpRetriever.java
se.chalmers.watchme.net.IMDBHandler.java
se.chalmers.watchme.net.ImageDownloadTask.java
se.chalmers.watchme.net.MovieSource.java
se.chalmers.watchme.net.NoEntityException.java
se.chalmers.watchme.notifications.Notifiable.java
se.chalmers.watchme.notifications.NotificationClient.java
se.chalmers.watchme.notifications.NotificationService.java
se.chalmers.watchme.notifications.NotifyService.java
se.chalmers.watchme.ui.ContentListFragment.java
se.chalmers.watchme.ui.DatePickerFragment.java
se.chalmers.watchme.ui.ImageDialog.java
se.chalmers.watchme.ui.MovieListFragment.java
se.chalmers.watchme.ui.TagListFragment.java
se.chalmers.watchme.utils.DateTimeUtils.java
se.chalmers.watchme.utils.ImageCache.java
se.chalmers.watchme.utils.MenuUtils.java
se.chalmers.watchme.utils.MovieHelper.java
se.chalmers.watchmetest.Constants.java
se.chalmers.watchmetest.activity.MainActivityTest.java
se.chalmers.watchmetest.activity.MovieDetailsActivityTest.java
se.chalmers.watchmetest.activity.SearchableActivityTest.java
se.chalmers.watchmetest.activity.TabsAdapterTest.java
se.chalmers.watchmetest.activity.TagMovieListActivityTest.java
se.chalmers.watchmetest.database.WatchMeContentProviderTest.java
se.chalmers.watchmetest.model.MovieTest.java
se.chalmers.watchmetest.model.TagTest.java
se.chalmers.watchmetest.net.HttpRetrieverTest.java
se.chalmers.watchmetest.net.IMDBHandlerTest.java
se.chalmers.watchmetest.ui.MovieListFragmentTest.java
se.chalmers.watchmetest.ui.TagListFragmentTest.java
se.chalmers.watchmetest.util.DateTimeUtilsTest.java
se.chalmers.watchmetest.util.MovieHelperTest.java