Android Open Source - AudioBook Browser Activity Test






From Project

Back to project page AudioBook.

License

The source code is released under:

Creative Commons Legal Code Attribution-NonCommercial 3.0 Unported CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT C...

If you think the Android project AudioBook 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

/**
 *  This work is licensed under the Creative Commons Attribution-NonCommercial-
 *  NoDerivs 3.0 Unported License. To view a copy of this license, visit
 *  http://creativecommons.org/licenses/by-nc-nd/3.0/ or send a letter to 
 *  Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 
 *  94041, USA./*from   ww  w .  j  ava2 s.c  o  m*/
 * 
 *  Use of this work is permitted only in accordance with license rights granted.
 *  Materials provided "AS IS"; no representations or warranties provided.
 * 
 *  Copyright ? 2012 Marcus Parkkinen, Aki K?kel?, Fredrik ?hs.
 **/

package edu.chalmers.dat255.audiobookplayer.view;

import android.test.ActivityInstrumentationTestCase2;
import android.test.TouchUtils;
import android.test.ViewAsserts;
import android.test.suitebuilder.annotation.SmallTest;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ListView;
import edu.chalmers.dat255.audiobookplayer.R;

/**
 * Tests the BrowserActivity class.
 * 
 * @author Fredrik ?hs
 * 
 */
public class BrowserActivityTest extends
    ActivityInstrumentationTestCase2<BrowserActivity> {
  private ListView browserListView;
  private BrowserActivity bActivity;
  private Button createBookButton;

  /**
   * @param name
   */
  public BrowserActivityTest(String name) {
    super(BrowserActivity.class);
    setName(name);
  }

  /*
   * (non-Javadoc)
   * 
   * @see android.test.ActivityInstrumentationTestCase2#setUp()
   */
  @SmallTest
  @Override
  protected void setUp() {
    try {
      super.setUp();
    } catch (Exception e) {
      // catch exceptions from super.setUp() and fail
      fail("setUp failed + " + e.getMessage());
    }
    bActivity = getActivity();
    assertNotNull("BrowserActivity null", bActivity);
    browserListView = (ListView) bActivity.findViewById(R.id.browserList);
    assertNotNull("BrowserActivity browserList null", browserListView);
    createBookButton = (Button) bActivity.findViewById(R.id.createBook);
    assertNotNull("BrowserActivity createBook null", createBookButton);

  }

  /**
   * Test method for
   * {@link edu.chalmers.dat255.audiobookplayer.view.BrowserActivity#onCreate(android.os.Bundle)}
   * .
   */
  @SmallTest
  public void testOnCreateBundle() {
    assertNotNull(bActivity);
  }

  /**
   * Asserts that all fields are visible on the screen.
   */
  @SmallTest
  public void testFieldsOnScreen() {
    final View origin = bActivity.getWindow().getDecorView();
    ViewAsserts.assertOnScreen(origin, browserListView);
    ViewAsserts.assertOnScreen(origin, createBookButton);
  }

  /**
   * Asserts that the list was filled
   */
  public void testListViewFilled() {
    assertTrue("browserListView not filed",
        browserListView.getChildCount() > 0);
  }

  /**
   * Asserts that checkboxes can be clicked to be selected and that they are
   * initiated as false
   */
  public void testCheckBox() {
    for (int i = 0; i < browserListView.getChildCount(); i++) {
      CheckBox cb = (CheckBox) browserListView.getChildAt(i)
          .findViewById(R.id.checkBox);
      assertNotNull("checkbox null", cb);
      assertFalse("checkbox initiated as true", cb.isChecked());
      TouchUtils.clickView(this, cb);
      ViewAsserts.assertOnScreen(browserListView.getChildAt(i), cb);
      assertTrue("checkbox could not check", cb.isChecked());
    }
  }

  /**
   * Tests that a folder is clickable. This requires the device to have at
   * least one audio file within a folder (not directly on sdcard).
   */
  public void testClickFolder() {
    View child = browserListView.getChildAt(0);
    String preString = child.toString();
    TouchUtils.clickView(this, child);
    View clicked = browserListView.getChildAt(0);
    assertNotNull("Clicked null", clicked);
    // assert the file was clicked. Variable clicked will be a view with the
    // title ".." and the description "Parent Folder"
    assertFalse(
        "Clicked did not change (this test requires there to be at least one audio file within a directory).",
        preString.equals(clicked.toString()));
  }

  /**
   * Tests whether the button to create a new book works.
   */
  public void testCreateButton() {
    for (int i = 0; i < browserListView.getChildCount(); i++) {
      CheckBox cb = (CheckBox) browserListView.getChildAt(i)
          .findViewById(R.id.checkBox);
      if (!cb.isChecked()) {
        TouchUtils.clickView(this, cb);
      }
      assertTrue(cb.isChecked());
    }
    // BookCreator's Bookshelf is null, bypass this
    // somehow
    // As bookshelf is null in BookCreator and there seems to be no possible
    // way to
    // check whether a toast was displayed or not, this method is deemed to
    // be too hard to implement.
    // TouchUtils.clickView(this,createBookButton);-
  }

}




Java Source Code List

edu.chalmers.dat255.audiobookplayer.constants.Constants.java
edu.chalmers.dat255.audiobookplayer.constants.PlaybackStatus.java
edu.chalmers.dat255.audiobookplayer.ctrl.BookshelfControllerTest.java
edu.chalmers.dat255.audiobookplayer.ctrl.BookshelfController.java
edu.chalmers.dat255.audiobookplayer.ctrl.PlayerControllerTest.java
edu.chalmers.dat255.audiobookplayer.ctrl.PlayerController.java
edu.chalmers.dat255.audiobookplayer.instrumentation.AllTests.java
edu.chalmers.dat255.audiobookplayer.interfaces.IBookUpdates.java
edu.chalmers.dat255.audiobookplayer.interfaces.IBookshelfEvents.java
edu.chalmers.dat255.audiobookplayer.interfaces.IBookshelfGUIEvents.java
edu.chalmers.dat255.audiobookplayer.interfaces.IPlayerEvents.java
edu.chalmers.dat255.audiobookplayer.interfaces.ITrackUpdates.java
edu.chalmers.dat255.audiobookplayer.model.BookTest.java
edu.chalmers.dat255.audiobookplayer.model.Book.java
edu.chalmers.dat255.audiobookplayer.model.BookshelfTest.java
edu.chalmers.dat255.audiobookplayer.model.Bookshelf.java
edu.chalmers.dat255.audiobookplayer.model.TagTest.java
edu.chalmers.dat255.audiobookplayer.model.Tag.java
edu.chalmers.dat255.audiobookplayer.model.TrackTest.java
edu.chalmers.dat255.audiobookplayer.model.Track.java
edu.chalmers.dat255.audiobookplayer.util.BookCreatorTest.java
edu.chalmers.dat255.audiobookplayer.util.BookCreator.java
edu.chalmers.dat255.audiobookplayer.util.BookshelfHandlerTest.java
edu.chalmers.dat255.audiobookplayer.util.BookshelfHandler.java
edu.chalmers.dat255.audiobookplayer.util.FileParserTest.java
edu.chalmers.dat255.audiobookplayer.util.FileParser.java
edu.chalmers.dat255.audiobookplayer.util.JsonParserTest.java
edu.chalmers.dat255.audiobookplayer.util.JsonParser.java
edu.chalmers.dat255.audiobookplayer.util.TextFormatterTest.java
edu.chalmers.dat255.audiobookplayer.util.TextFormatter.java
edu.chalmers.dat255.audiobookplayer.util.TrackCreatorTest.java
edu.chalmers.dat255.audiobookplayer.util.TrackCreator.java
edu.chalmers.dat255.audiobookplayer.view.BookshelfFragment.java
edu.chalmers.dat255.audiobookplayer.view.BrowserActivityTest.java
edu.chalmers.dat255.audiobookplayer.view.BrowserActivity.java
edu.chalmers.dat255.audiobookplayer.view.MainActivity.java
edu.chalmers.dat255.audiobookplayer.view.PlayerFragment.java
edu.chalmers.dat255.audiobookplayer.view.ViewPagerAdapter.java