Beispiel #1
0
  @Test
  public void testTellAFriend() {
    openDrawer(R.id.drawer_layout);
    Intents.intending(
            AllOf.allOf(
                hasAction(Intent.ACTION_CHOOSER),
                hasExtra(Intent.EXTRA_TITLE, mActivity.getString(R.string.share_via))))
        .respondWith(new Instrumentation.ActivityResult(Activity.RESULT_OK, null));

    onView(
            allOf(
                is(instanceOf(NavigationMenuItemView.class)),
                withText(R.string.action_tellafriend)))
        .perform(click());
    intended(
        allOf(
            hasAction(Intent.ACTION_CHOOSER),
            hasExtra(Intent.EXTRA_TITLE, mActivity.getString(R.string.share_via))));
  }
 /**
  * Test to show assertion using "org.junit.Assert.assertThat()" method<br>
  *
  * @see http ://junit.org/junit/javadoc/4.5/org/hamcrest/core/package-frame.html
  */
 @Test
 public void showAssertThat() {
   String localVar = null;
   // Assert True if "this.bean" object is a instance of "ProcessingBean"
   // class
   Assert.assertThat(this.bean, IsInstanceOf.instanceOf(ProcessingBean.class));
   // Assert True if at least one assert included in the "AnyOf" operator
   // is True
   Assert.assertThat(
       this.bean.getMessage(),
       AnyOf.anyOf(IsEqual.equalTo("Hello World !"), IsNot.not(IsEqual.equalTo("Hello World !"))));
   // Assert True if all assert included in the "AllOf" operator are True
   Assert.assertThat(
       this.bean.getMessage(),
       AllOf.allOf(IsEqual.equalTo("Hello World !"), Is.is("Hello World !")));
   // Assert True if "this.bean" is the same instance than
   // "this.bean.getInstance()"
   Assert.assertThat(this.bean, IsSame.sameInstance(this.bean.getInstance()));
   // Assert True if "localVar" is null
   Assert.assertThat(localVar, IsNull.nullValue());
   // Assert True if "localVar" is not null
   localVar = "value";
   Assert.assertThat(localVar, IsNull.notNullValue());
 }