Android Open Source - watchme Movie Details 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;
/* w w w . j av a  2  s.  c o  m*/
import se.chalmers.watchme.R;
import se.chalmers.watchme.activity.MainActivity;
import se.chalmers.watchme.activity.MovieDetailsActivity;
import se.chalmers.watchme.database.DatabaseHelper;
import se.chalmers.watchmetest.Constants;
import android.support.v4.view.ViewPager;
import android.test.ActivityInstrumentationTestCase2;
import android.view.View;
import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.TextView;

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

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

  Solo solo;
  DatabaseHelper dbh;

  public MovieDetailsActivityTest() {
    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();
    dbh.onUpgrade(dbh.getWritableDatabase(), 1, 1);
  }

  /**
   * Test if details view shows the correct details of a movie
   */
  public void testViewDetails() {
    // Clear list of movies stored in database
    dbh.onUpgrade(dbh.getWritableDatabase(), 1, 1);

    solo.waitForActivity("MainActivity");

    // Add movie
    solo.clickOnActionBarItem(R.id.menu_main_add_movie);
    solo.waitForActivity("AddMovieActivity");
    solo.enterText(Constants.TITLE_FIELD, "TEST_MOVIE");
    solo.setProgressBar(Constants.RATING_BAR, 1);
    solo.clickOnView(solo.getView(R.id.release_date_button));
    solo.waitForText("Done");
    solo.setDatePicker(Constants.DATE_PICKER, 2014 - 1, 12, 24);
    solo.clickOnText("Done");
    solo.waitForDialogToClose(Constants.WAIT_FOR_DIALOG_TO_CLOSE_TIME);
    solo.enterText(Constants.TAG_FIELD, "Action");
    solo.enterText(Constants.NOTE_FIELD, "Mum said I'd like this");
    solo.clickOnActionBarItem(R.id.menu_add_movie);

    // Navigate to details view
    solo.waitForActivity("MainActivity");
    solo.clickOnText("TEST_MOVIE");
    boolean isMovieDetailsActivityViewed = solo
        .waitForActivity("MovieDetailsActivity");
    assertTrue(isMovieDetailsActivityViewed);

    // Check if correct details are viewed
    boolean isTitleFound = solo.searchText("TEST_MOVIE");
    assertTrue(isTitleFound);

    RatingBar ratingBar = (RatingBar) solo.getView(R.id.my_rating_bar);
    assertTrue(ratingBar.getRating() == 1);

    TextView releaseDateLabel = (TextView) solo.getView(R.id.releaseDate);
    assertTrue(releaseDateLabel.getText().equals("24 Jan, 2014"));

    EditText noteField = (EditText) solo.getView(R.id.note_field_details);
    assertTrue(noteField.getText().toString()
        .equals("Mum said I'd like this"));

    EditText tagField = (EditText) solo.getView(R.id.tag_field_details);
    assertTrue(tagField.getText().toString().equals("action"));
  }

  /**
   * Test if it's possible to edit a movie's details
   */
  public void testEditDetails() {
    // Clear list of movies stored in database
    dbh.onUpgrade(dbh.getWritableDatabase(), 1, 1);

    solo.waitForActivity("MainActivity");

    // Add movie
    solo.clickOnActionBarItem(R.id.menu_main_add_movie);
    solo.waitForActivity("AddMovieActivity");
    solo.enterText(Constants.TITLE_FIELD, "TEST_MOVIE");
    solo.clickOnActionBarItem(R.id.menu_add_movie);

    // Navigate to details view
    solo.waitForActivity("MainActivity");
    solo.clickOnText("TEST_MOVIE");
    solo.waitForActivity("MovieDetailsActivity");

    // Check that correct details are viewed
    RatingBar ratingBar = (RatingBar) solo.getView(R.id.my_rating_bar);
    TextView releaseDateLabel = (TextView) solo.getView(R.id.releaseDate);
    EditText noteField = (EditText) solo.getView(R.id.note_field_details);
    EditText tagField = (EditText) solo.getView(R.id.tag_field_details);

    assertTrue(ratingBar.getRating() == 0);
    assertFalse(releaseDateLabel.getText().equals("24 Jan, 2014"));
    assertTrue(noteField.getText().toString().equals(""));
    assertTrue(tagField.getText().toString().equals(""));

    // Edit movie details
    solo.clickOnActionBarItem(R.id.menu_edit);
    solo.setProgressBar(Constants.RATING_BAR, 1);
    solo.clickOnView(solo.getView(R.id.release_date_button));
    solo.waitForText("Done");
    solo.setDatePicker(Constants.DATE_PICKER, 2014 - 1, 12, 24);
    solo.clickOnText("Done");
    solo.waitForDialogToClose(Constants.WAIT_FOR_DIALOG_TO_CLOSE_TIME);
    solo.enterText(0, "Action");
    solo.enterText(1, "Mum said I'd like this");
    solo.clickOnActionBarItem(R.id.menu_save);

    // Navigate out from and back to details view
    solo.clickOnActionBarHomeButton();
    solo.waitForActivity("MainActivity");
    solo.clickOnText("TEST_MOVIE");
    solo.waitForActivity("MovieDetailsActivity");

    // Check if new details are viewed
    assertTrue(ratingBar.getRating() == 1);
    assertTrue(releaseDateLabel.getText().equals("24 Jan, 2014"));
    assertTrue(noteField.getText().toString()
        .equals("Mum said I'd like this"));
    assertTrue(tagField.getText().toString().equals("Action"));
  }
}




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