/** * Returns the most recently shown {@code Toast}. * * @return the most recently shown {@code Toast} */ public static Toast getLatestToast() { ShadowApplication shadowApplication = Shadow.extract(RuntimeEnvironment.application); List<Toast> shownToasts = shadowApplication.getShownToasts(); return (shownToasts.size() == 0) ? null : shownToasts.get(shownToasts.size() - 1); } }
/** * Returns the number of {@code Toast} requests that have been made during this test run * or since {@link #reset()} has been called. * * @return the number of {@code Toast} requests that have been made during this test run * or since {@link #reset()} has been called. */ public static int shownToastCount() { ShadowApplication shadowApplication = Shadow.extract(RuntimeEnvironment.application); return shadowApplication.getShownToasts().size(); }
@Implementation protected void show() { ShadowApplication shadowApplication = Shadow.extract(RuntimeEnvironment.application); shadowApplication.getShownToasts().add(toast); }
/** * Discards the recorded {@code Toast}s. Shown toasts are automatically cleared between * tests. This method allows the user to discard recorded toasts during the test in order to make assertions clearer * e.g: * * <pre> * * // Show a single toast * myClass.showToast(); * * assertThat(ShadowToast.shownToastCount()).isEqualTo(1); * ShadowToast.reset(); * * // Show another toast * myClass.showToast(); * * assertThat(ShadowToast.shownToastCount()).isEqualTo(1); * * </pre> */ public static void reset() { ShadowApplication shadowApplication = Shadow.extract(RuntimeEnvironment.application); shadowApplication.getShownToasts().clear(); }
/** * Returns the text of the most recently shown {@code Toast}. * * @return the text of the most recently shown {@code Toast} */ public static String getTextOfLatestToast() { ShadowApplication shadowApplication = Shadow.extract(RuntimeEnvironment.application); List<Toast> shownToasts = shadowApplication.getShownToasts(); if (shownToasts.isEmpty()) { return null; } else { Toast latestToast = shownToasts.get(shownToasts.size() - 1); ShadowToast shadowToast = Shadow.extract(latestToast); return shadowToast.text; } }
/** * Returns whether or not a particular custom {@code Toast} has been shown. * * @param message the message to search for * @param layoutResourceIdToCheckForMessage * the id of the resource that contains the toast messages * @return whether the {@code Toast} was requested */ public static boolean showedCustomToast(CharSequence message, int layoutResourceIdToCheckForMessage) { ShadowApplication shadowApplication = Shadow.extract(RuntimeEnvironment.application); for (Toast toast : shadowApplication.getShownToasts()) { String text = ((TextView) toast.getView().findViewById(layoutResourceIdToCheckForMessage)).getText().toString(); if (text.equals(message.toString())) { return true; } } return false; }
/** * query method that returns whether or not a particular {@code Toast} has been shown. * * @param message the message to search for * @return whether the {@code Toast} was requested */ public static boolean showedToast(CharSequence message) { ShadowApplication shadowApplication = Shadow.extract(RuntimeEnvironment.application); for (Toast toast : shadowApplication.getShownToasts()) { ShadowToast shadowToast = Shadow.extract(toast); String text = shadowToast.text; if (text != null && text.equals(message.toString())) { return true; } } return false; }
/** * Returns the number of {@code Toast} requests that have been made during this test run * or since {@link #reset()} has been called. * * @return the number of {@code Toast} requests that have been made during this test run * or since {@link #reset()} has been called. */ public static int shownToastCount() { return shadowOf(RuntimeEnvironment.application).getShownToasts().size(); }
/** * Non-Android accessor that returns the most recently shown {@code Toast} * * @return the most recently shown {@code Toast} */ public static Toast getLatestToast() { List<Toast> shownToasts = shadowOf(RuntimeEnvironment.application).getShownToasts(); return (shownToasts.size() == 0) ? null : shownToasts.get(shownToasts.size() - 1); } }
/** * Non-Android accessor that returns the number of {@code Toast} requests that have been made during this test run * or since {@link #reset()} has been called. * * @return the number of {@code Toast} requests that have been made during this test run * or since {@link #reset()} has been called. */ public static int shownToastCount() { return shadowOf(RuntimeEnvironment.application).getShownToasts().size(); }
/** * Non-Android accessor that discards the recorded {@code Toast}s */ public static void reset() { shadowOf(RuntimeEnvironment.application).getShownToasts().clear(); }
/** * Non-Android accessor that returns the most recently shown {@code Toast} * * @return the most recently shown {@code Toast} */ public static Toast getLatestToast() { List<Toast> shownToasts = shadowOf(RuntimeEnvironment.application).getShownToasts(); return (shownToasts.size() == 0) ? null : shownToasts.get(shownToasts.size() - 1); } }
/** * Returns the most recently shown {@code Toast}. * * @return the most recently shown {@code Toast} */ public static Toast getLatestToast() { List<Toast> shownToasts = shadowOf(RuntimeEnvironment.application).getShownToasts(); return (shownToasts.size() == 0) ? null : shownToasts.get(shownToasts.size() - 1); } }
/** * Non-Android accessor that returns the number of {@code Toast} requests that have been made during this test run * or since {@link #reset()} has been called. * * @return the number of {@code Toast} requests that have been made during this test run * or since {@link #reset()} has been called. */ public static int shownToastCount() { return shadowOf(RuntimeEnvironment.application).getShownToasts().size(); }
/** * Returns the number of {@code Toast} requests that have been made during this test run * or since {@link #reset()} has been called. * * @return the number of {@code Toast} requests that have been made during this test run * or since {@link #reset()} has been called. */ public static int shownToastCount() { ShadowApplication shadowApplication = Shadow.extract(RuntimeEnvironment.application); return shadowApplication.getShownToasts().size(); }
/** * Returns the most recently shown {@code Toast}. * * @return the most recently shown {@code Toast} */ public static Toast getLatestToast() { ShadowApplication shadowApplication = Shadow.extract(RuntimeEnvironment.application); List<Toast> shownToasts = shadowApplication.getShownToasts(); return (shownToasts.size() == 0) ? null : shownToasts.get(shownToasts.size() - 1); } }
/** * Returns the text of the most recently shown {@code Toast}. * * @return the text of the most recently shown {@code Toast} */ public static String getTextOfLatestToast() { List<Toast> shownToasts = shadowOf(RuntimeEnvironment.application).getShownToasts(); return (shownToasts.size() == 0) ? null : shadowOf(shownToasts.get(shownToasts.size() - 1)).text; }
/** * Non-Android accessor that returns the text of the most recently shown {@code Toast} * * @return the text of the most recently shown {@code Toast} */ public static String getTextOfLatestToast() { List<Toast> shownToasts = shadowOf(RuntimeEnvironment.application).getShownToasts(); return (shownToasts.size() == 0) ? null : shadowOf(shownToasts.get(shownToasts.size() - 1)).text; }
/** * Non-Android accessor that returns the text of the most recently shown {@code Toast} * * @return the text of the most recently shown {@code Toast} */ public static String getTextOfLatestToast() { List<Toast> shownToasts = shadowOf(RuntimeEnvironment.application).getShownToasts(); return (shownToasts.size() == 0) ? null : shadowOf(shownToasts.get(shownToasts.size() - 1)).text; }
@Implementation protected void show() { ShadowApplication shadowApplication = Shadow.extract(RuntimeEnvironment.application); shadowApplication.getShownToasts().add(toast); }