@Before
  public void setUpModel() {
    // Create a fake model to simulate a keynote session.
    SessionDetailModel fakeModel =
        new FakeSessionDetailModelKeynote(
            mSessionUri,
            mActivityRule.getActivity().getApplicationContext(),
            new SessionsHelper(mActivityRule.getActivity()));

    // Set up the presenter with the fake model.
    final PresenterFragmentImpl presenter =
        mActivityRule
            .getActivity()
            .addPresenterFragment(
                R.id.session_detail_frag,
                fakeModel,
                SessionDetailModel.SessionDetailQueryEnum.values(),
                SessionDetailModel.SessionDetailUserActionEnum.values());

    mActivityRule
        .getActivity()
        .runOnUiThread(
            new Runnable() {

              @Override
              public void run() {
                presenter.getLoaderManager().restartLoader(0, null, presenter);
              }
            });
  }
예제 #2
0
  @Before
  public void setUp() throws Exception {
    context = mActivityRule.getActivity();

    if (hostInfo == null) // We only need to fill the database the first time
    hostInfo = Database.fill(context);

    contentResolver = mActivityRule.getActivity().getContentResolver();
  }
  @Test
  public void testSingleStation() throws InterruptedException {
    when(availableStationsManager.isAvailable(any(Station.class))).thenReturn(true);
    defineMock(parseService, new StationList(new Station(0, 0, "aaaa")));

    rule.launchActivity(null);

    onView(withId(R.id.total_count)).check(matches(withText("1")));

    Spoon.screenshot(rule.getActivity(), "Single_station");
  }
  @Test
  public void testNoData() throws InterruptedException {
    when(availableStationsManager.isAvailable(any(Station.class))).thenReturn(true);
    defineMock(parseService, new StationList());

    rule.launchActivity(null);

    onView(withId(R.id.no_data)).check(matches(isDisplayed()));

    Spoon.screenshot(rule.getActivity(), "No_data");
  }
 @Test
 public void aboutMenuClick_ShowAboutBookDashScreen() {
   // When
   NavigationUtils.selectNavDrawItem(mActivityTestRule.getActivity(), R.id.action_about);
   // Then
   onView(withText(R.string.title_activity_about)).check(matches(isDisplayed()));
 }
  @Test
  public void contributorsClicked_ShowThanksPopover() {

    // When
    NavigationUtils.selectNavDrawItem(mActivityTestRule.getActivity(), R.id.action_thanks);
    // Then
    onView(withText("Contributors")).inRoot(isDialog()).check(matches(isDisplayed()));
  }
  @Test
  public void contributorsOkClick_HideThanksPopover() {
    // When
    NavigationUtils.selectNavDrawItem(mActivityTestRule.getActivity(), R.id.action_thanks);

    // Then
    onView(withText(android.R.string.ok)).perform(click());
  }
  @Test
  public void enviamosUnDatito() {
    Intent intent = new Intent();
    intent.putExtra("data", THIS_IS_MY_BOMB);
    activityTestRule.launchActivity(intent);

    onView(withId(R.id.txt_receiver)).check(matches(withText(THIS_IS_MY_BOMB)));
  }
 @Test
 public void preConditions() {
   ImageDetailActivity activity = activityRule.launchActivity(intent);
   onView(withId(R.id.container))
       .check(matches(ViewMatchers.withContentDescription(R.string.detail_container)));
   String args = activity.getIntent().getStringExtra(ImageDetailActivity.EXTRA_CONTENT);
   assertEquals(args, DataHolder.LIST_ITEM_JSON);
 }
예제 #10
0
  @Test
  public void testDisabled() {
    ViewUtils.checkViewIsDisplayed(R.id.mapView);
    MapboxMap mapboxMap = rule.getActivity().getMapboxMap();

    onView(withId(R.id.logoView))
        .perform(new DisableAction(mapboxMap))
        .check(matches(not(isDisplayed())));
  }
 @Test
 public void nullCommentHandling() {
   HashMap<String, String> map = new HashMap<>();
   map.put(
       FlickrURL.COMMENT_LIST, "{\"comments\":{\"photo_id\":\"21043155476\"},\"stat\":\"ok\"}");
   setupMockServer(map);
   activityRule.launchActivity(intent);
   SystemClock.sleep(3000);
   onView(withContentDescription("No Comment")).check(matches(withText(R.string.no_comment)));
 }
  @Test
  public void shouldDisplayCardNumberError() {
    Intent intent = new Intent();
    intent.putExtra(Judo.JUDO_OPTIONS, getJudo().build());

    testRule.launchActivity(intent);

    onView(withId(R.id.card_number_edit_text)).perform(typeText("1111111111111111"));

    onView(withText("Check card number")).check(matches(isDisplayed()));

    onView(withId(R.id.pay_button)).check(matches(isNotDisplayed()));
  }
예제 #13
0
  @Test
  public void testPostsShowAndAreScrollableInFeed() {
    List<Long> postIdList = MockModelsUtil.createMockPostIdList(20);
    List<Post> postList = new ArrayList<>();
    for (Long id : postIdList) {
      postList.add(MockModelsUtil.createMockStoryWithId(id));
    }

    stubMockPosts(postIdList, postList);
    main.launchActivity(null);

    checkPostsDisplayOnRecyclerView(postList);
  }
  @Test
  public void shouldDisplayExpiryDateError() {
    Intent intent = new Intent();
    intent.putExtra(Judo.JUDO_OPTIONS, getJudo().build());

    testRule.launchActivity(intent);

    onView(withId(R.id.expiry_date_edit_text)).perform(typeText("1215"));

    onView(withText("Check expiry date")).check(matches(isDisplayed()));

    onView(withId(R.id.pay_button)).check(matches(isNotDisplayed()));
  }
예제 #15
0
  @Test
  public void testJobPostHasViewButton() throws Exception {
    List<Long> postIdList = new ArrayList<>();
    Post mockPost = MockModelsUtil.createMockJobWithTitle("Post with url");
    postIdList.add(mockPost.id);
    when(component.getMockHackerNewsService().getTopStories())
        .thenReturn(Observable.just(postIdList));
    when(component.getMockHackerNewsService().getStoryItem(mockPost.id.toString()))
        .thenReturn(Observable.just(mockPost));

    Intent i = new Intent(MainActivity.getStartIntent(InstrumentationRegistry.getTargetContext()));
    main.launchActivity(i);
    onView(withId(R.id.text_view_post)).check(matches(isDisplayed()));
  }
 @Test
 public void testDescriptionExpand() {
   setupMockServer(null);
   activityRule.launchActivity(intent);
   TimingIdlingResource idlingResource =
       new TimingIdlingResource(3000); // wait dummy network operation
   Espresso.registerIdlingResources(idlingResource);
   onView(withId(R.id.description))
       .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
   onView(withId(R.id.description_parent)).perform(click());
   onView(withId(R.id.description))
       .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
   Espresso.unregisterIdlingResources(idlingResource);
 }
  @Test
  public void testError() throws InterruptedException {
    when(availableStationsManager.isAvailable(any(Station.class))).thenReturn(true);
    doAnswer(
            new Answer<Object>() {

              private boolean first = true;

              @Override
              public Object answer(InvocationOnMock invocation) throws Throwable {
                Callback<StationList> callback =
                    (Callback<StationList>) invocation.getArguments()[0];
                if (first) {
                  callback.failure(null);
                  first = false;
                } else {
                  callback.success(new StationList(new Station(0, 0, "aaaa")), null);
                }
                return null;
              }
            })
        .when(parseService)
        .getStations(any(Callback.class));

    rule.launchActivity(null);

    Spoon.screenshot(rule.getActivity(), "Error");

    onView(withId(R.id.error_layout)).check(matches(isDisplayed()));

    onView(withId(R.id.retry)).perform(click());

    onView(withId(R.id.error_layout)).check(matches(not(isDisplayed())));
    onView(withId(R.id.total_count)).check(matches(withText("1")));

    Spoon.screenshot(rule.getActivity(), "Reload_after_error");
  }
  @Test
  public void checkPreconditions() {
    // Check the session uri
    assertEquals(mSessionUri, mActivityRule.getActivity().getSessionUri());

    // Check the presenter exists
    assertNotNull(
        mActivityRule
            .getActivity()
            .getFragmentManager()
            .findFragmentByTag(BaseActivity.PRESENTER_TAG));

    PresenterFragmentImpl presenter =
        (PresenterFragmentImpl)
            mActivityRule
                .getActivity()
                .getFragmentManager()
                .findFragmentByTag(BaseActivity.PRESENTER_TAG);

    // Check the model is the injected fake implementation. Also check, initial queries and
    // valid user actions of the Presenter. No need to check the UpdatableView because other
    // tests will fail if expected views aren't present
    assertThat(
        "The presenter model should be an instance of SessionDetailModel",
        presenter.getModel(),
        instanceOf(SessionDetailModel.class));
    assertTrue(
        Arrays.equals(
            SessionDetailModel.SessionDetailQueryEnum.values(),
            presenter.getInitialQueriesToLoad()));
    assertTrue(
        Arrays.equals(
            SessionDetailModel.SessionDetailUserActionEnum.values(),
            presenter.getValidUserActions()));
    assertThat(((SessionDetailModel) presenter.getModel()).getSessionTitle(), is(FAKE_TITLE));
  }
예제 #19
0
  @Test
  public void listOfRibotsShows() {
    List<Ribot> mockRibots = TestDataFactory.makeListRibots(20);
    when(component.getMockRibotsService().getRibots()).thenReturn(Observable.just(mockRibots));

    main.launchActivity(null);

    int position = 0;
    for (Ribot mockRibot : mockRibots) {
      onView(withId(R.id.recycler_view)).perform(RecyclerViewActions.scrollToPosition(position));
      String name =
          String.format("%s %s", mockRibot.profile.name.first, mockRibot.profile.name.last);
      onView(withText(name)).check(matches(isDisplayed()));
      onView(withText(mockRibot.profile.email)).check(matches(isDisplayed()));
      position++;
    }
  }
  @Test
  public void shouldDisplaySubmitButtonWhenFormValid() {
    Intent intent = new Intent();
    intent.putExtra(Judo.JUDO_OPTIONS, getJudo().build());

    testRule.launchActivity(intent);

    onView(withId(R.id.pay_button)).check(matches(isNotDisplayed()));

    onView(withId(R.id.card_number_edit_text)).perform(typeText("4976000000003436"));

    onView(withId(R.id.expiry_date_edit_text)).perform(typeText("1220"));

    onView(withId(R.id.security_code_edit_text)).perform(typeText("452"));

    onView(withId(R.id.pay_button)).check(matches(isDisplayed()));
  }
 @Test
 public void goUserPageFromComment() {
   setupMockServer(null);
   activityRule.launchActivity(intent);
   TimingIdlingResource idlingResource =
       new TimingIdlingResource(3000); // wait dummy network operation
   Espresso.registerIdlingResources(idlingResource);
   onView(withId(R.id.comment_parent)).perform(clickComment());
   Espresso.unregisterIdlingResources(idlingResource);
   Instrumentation.ActivityMonitor receiverActivityMonitor =
       InstrumentationRegistry.getInstrumentation()
           .addMonitor(UserActivity.class.getName(), null, false);
   Activity activity = receiverActivityMonitor.waitForActivityWithTimeout(1000);
   assertEquals("Launched Activity is not UserActivity", UserActivity.class, activity.getClass());
   onView(withText("¡! Nature B■x !¡")).check(matches(isDisplayed()));
   pressBack();
   SystemClock.sleep(2000);
 }
  @Test
  public void testSelectMultipleActivities() {
    String activityName1 = "Test Activity 1";
    String activityName2 = "Test Activity 2";
    Calendar cal = Calendar.getInstance();
    Task t1 = new Task("01", activityName1, 60, cal, cal.getTimeInMillis(), cal, 30);
    Task t2 = new Task("01", activityName2, 60, cal, cal.getTimeInMillis(), cal, 30);
    ArrayList<Task> arrayList = new ArrayList<Task>();
    arrayList.add(t1);
    arrayList.add(t2);
    SelectTasksAdapter adapter = new SelectTasksAdapter(ctx, arrayList);
    adapter.notifyDataSetChanged();

    // Setting the activity to use the adapter with test data
    SelectTasksActivity sa = main.getActivity();
    sa.setAdapter(adapter);

    // check activity 1 is added in listView
    onView(withId(R.id.select_tasks_recycler_view))
        .check(matches(hasDescendant(withText(activityName1))));
    onView(withText(activityName1)).perform(click());

    // check activity 2 is added in listView
    onView(withId(R.id.select_tasks_recycler_view))
        .check(matches(hasDescendant(withText(activityName2))));
    onView(withText(activityName2)).perform(click());

    // check toast is displayed
    onView(withId(R.id.action_done)).perform(click());

    // Set a progress of 10 to the activity
    onView(withId(R.id.add_time_to_task_seekbar)).perform(setProgress(1));

    // Press next button
    onView(withId(R.id.add_time_to_task_nextBtn)).perform(click());

    // Set a progress of 10 to the activity
    onView(withId(R.id.add_time_to_task_seekbar)).perform(setProgress(1));

    // Press next button
    onView(withId(R.id.add_time_to_task_nextBtn)).perform(click());
  }
  @Test
  public void loadBookInfo_DisplayBookInformation() {
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    BookDetailParcelable bookDetailParcelable = new BookDetailParcelable();
    bookDetailParcelable.setBookDetailObjectId(BOOK_OBJ_ID);
    bookDetailParcelable.setBookTitle("Searching for Spring");
    bookDetailParcelable.setBookImageUrl(
        "http://riggaroo.co.za/bookdash/3-fishgift/xhosa/1-cover.jpg");
    intent.putExtra(BookInfoActivity.BOOK_PARCEL, bookDetailParcelable);
    activityTestRule.launchActivity(intent);

    onView(withText("Searching for Spring"))
        .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));

    onView(withText("Rebecca Franks"))
        .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
    onView(withText("Johan Smith"))
        .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
  }
예제 #24
0
  @Test
  public void testLikeClickableJailed() {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();

    SharedPreferences sharedPreferences =
        context.getSharedPreferences(JoinActivity.PREFS_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.clear();
    editor.commit();

    editor.putString("logged", "logged");
    editor.putInt("userId", -1);
    editor.putBoolean("jailed", true);
    editor.putInt("experience", 1000000);
    editor.commit();

    Intent intent = new Intent(context, MainActivity.class);
    intent.putExtra(MainActivity.ROOM_NAME, "testroom");
    mainActivityActivityTestRule.launchActivity(intent);
  }
 /** TODO: Passed List data and detail data is wrong item */
 @Test
 public void checkDetailInfo_isSet() {
   setupMockServer(null);
   activityRule.launchActivity(intent);
   onView(withId(R.id.title))
       .check(matches(withText("A Quiet Evening"))); // we know its title from list
   onView(withId(R.id.user_name)).check(matches(withText("")));
   onView(withId(R.id.description)).check(matches(withText("")));
   onView(withId(R.id.date_text)).check(matches(withText("")));
   TimingIdlingResource idlingResource =
       new TimingIdlingResource(3000); // wait dummy network operation
   Espresso.registerIdlingResources(idlingResource);
   onView(withId(R.id.title)).check(matches(withText("Sundown on the Oregon Coast")));
   onView(withId(R.id.user_name)).check(matches(withText("Cole Chase Photography")));
   onView(withId(R.id.description)).check(matches(startsWith("I was treated to this")));
   onView(withId(R.id.date_text)).check(matches(withText("Posted on 2015-08-02 22:40:28")));
   onView(withId(R.id.comment_parent)).check(matches(withChildOn(0, "C'est magnifique !")));
   onView(withId(R.id.comment_parent)).check(matches(withChildOn(1, "A wonderful moment")));
   onView(withId(R.id.comment_parent)).check(matches(withChildOn(2, "beautiful capture Cole")));
   onView(withId(R.id.comment_parent)).check(matches(withChildOn(3, "See All 35 Comments")));
   Espresso.unregisterIdlingResources(idlingResource);
 }
 @BeforeClass
 public static void setUp() {
   ms = new RottenTomatoesJSON(activity.getActivity());
 }
 @Before
 public void setActivity() {
   mActivity = mActivityRule.getActivity();
 }
 @Before
 public void setUp() throws Exception {
   mainActivity = act.getActivity();
 }
 @After
 public void teardown() {
   mActivityTestRule.getActivity().getContentResolver().delete(TaskList.URI, null, null);
 }
 @Before
 public void setUp() {
   RxSwipeDismissBehaviorTestActivity activity = activityRule.getActivity();
   view = activity.view;
 }