Package org.robolectric.shadows
Class ShadowToast
java.lang.Object
org.robolectric.shadows.ShadowToast
@Implements(android.widget.Toast.class) public class ShadowToast extends Object
-
Constructor Summary
Constructors Constructor Description ShadowToast() -
Method Summary
Modifier and Type Method Description protected void__constructor__(Context context)protected voidcancel()protected intgetDuration()protected intgetGravity()static ToastgetLatestToast()Returns the most recently shownToast.static StringgetTextOfLatestToast()Returns the text of the most recently shownToast.protected ViewgetView()protected intgetXOffset()protected intgetYOffset()booleanisCancelled()protected static ToastmakeText(Context context, int resId, int duration)protected static ToastmakeText(Context context, CharSequence text, int duration)static voidreset()Discards the recordedToasts.protected voidsetDuration(int duration)protected voidsetGravity(int gravity, int xOffset, int yOffset)protected voidsetText(int resId)protected voidsetText(CharSequence text)protected voidsetView(View view)protected voidshow()static booleanshowedCustomToast(CharSequence message, int layoutResourceIdToCheckForMessage)Returns whether or not a particular customToasthas been shown.static booleanshowedToast(CharSequence message)query method that returns whether or not a particularToasthas been shown.static intshownToastCount()Returns the number ofToastrequests that have been made during this test run or sincereset()has been called.
-
Constructor Details
-
ShadowToast
public ShadowToast()
-
-
Method Details
-
__constructor__
-
makeText
-
makeText
-
show
-
setText
-
setText
-
setView
-
getView
-
setGravity
-
getGravity
-
getXOffset
-
getYOffset
-
setDuration
-
getDuration
-
cancel
-
isCancelled
public boolean isCancelled() -
reset
public static void reset()Discards the recordedToasts. 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:// Show a single toast myClass.showToast(); assertThat(ShadowToast.shownToastCount()).isEqualTo(1); ShadowToast.reset(); // Show another toast myClass.showToast(); assertThat(ShadowToast.shownToastCount()).isEqualTo(1); -
shownToastCount
public static int shownToastCount()Returns the number ofToastrequests that have been made during this test run or sincereset()has been called.- Returns:
- the number of
Toastrequests that have been made during this test run or sincereset()has been called.
-
showedCustomToast
public static boolean showedCustomToast(CharSequence message, int layoutResourceIdToCheckForMessage)Returns whether or not a particular customToasthas been shown.- Parameters:
message- the message to search forlayoutResourceIdToCheckForMessage- the id of the resource that contains the toast messages- Returns:
- whether the
Toastwas requested
-
showedToast
query method that returns whether or not a particularToasthas been shown.- Parameters:
message- the message to search for- Returns:
- whether the
Toastwas requested
-
getTextOfLatestToast
Returns the text of the most recently shownToast.- Returns:
- the text of the most recently shown
Toast
-
getLatestToast
Returns the most recently shownToast.- Returns:
- the most recently shown
Toast
-