public ToastAssert hasDuration(int duration) { isNotNull(); int actualDuration = actual.getDuration(); assertThat(actualDuration) // .overridingErrorMessage("Expected duration <%s> but was <%s>.", duration, actualDuration) // .isEqualTo(duration); return this; }
@Test public void shouldHaveLongDuration() throws Exception { Toast toast = Toast.makeText(context, "long toast", Toast.LENGTH_LONG); assertThat(toast).isNotNull(); assertThat(toast.getDuration()).isEqualTo(Toast.LENGTH_LONG); }
@Test public void shouldHaveShortDuration() throws Exception { Toast toast = Toast.makeText(context, "short toast", Toast.LENGTH_SHORT); assertThat(toast).isNotNull(); assertThat(toast.getDuration()).isEqualTo(Toast.LENGTH_SHORT); }
@Test public void shouldMakeTextCorrectly() throws Exception { Toast toast = Toast.makeText(context, "short toast", Toast.LENGTH_SHORT); assertThat(toast).isNotNull(); assertThat(toast.getDuration()).isEqualTo(Toast.LENGTH_SHORT); toast.show(); assertThat(ShadowToast.getLatestToast()).isSameAs(toast); assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo("short toast"); assertThat(ShadowToast.showedToast("short toast")).isTrue(); }
public ToastAssert hasDuration(int duration) { isNotNull(); int actualDuration = actual.getDuration(); assertThat(actualDuration) // .overridingErrorMessage("Expected duration <%s> but was <%s>.", duration, actualDuration) // .isEqualTo(duration); return this; }
public class MyOwnToast extends Toast { public MyOwnToast(Toast toast) { //Code to initialize your toast from the argument toast //Probably something like this: this.setView(toast.getView()); this.setDuration(toast.getDuration()); //etc. for other get/set pairs in Toast } public static MyMakeText(Context context, CharSequence text, int duration) { return new MyOwnToast(Toast.makeText(context, text, duration)); } public void show() { //Your show override code, including super.show() } }