Class ShadowToast


  • @Implements(android.widget.Toast.class)
    public class ShadowToast
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      ShadowToast()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void __constructor__​(android.content.Context context)  
      protected void cancel()  
      protected int getDuration()  
      protected int getGravity()  
      static android.widget.Toast getLatestToast()
      Returns the most recently shown Toast.
      static java.lang.String getTextOfLatestToast()
      Returns the text of the most recently shown Toast.
      protected android.view.View getView()  
      protected int getXOffset()  
      protected int getYOffset()  
      boolean isCancelled()  
      protected static android.widget.Toast makeText​(android.content.Context context, int resId, int duration)  
      protected static android.widget.Toast makeText​(android.content.Context context, java.lang.CharSequence text, int duration)  
      static void reset()
      Discards the recorded Toasts.
      protected void setDuration​(int duration)  
      protected void setGravity​(int gravity, int xOffset, int yOffset)  
      protected void setText​(int resId)  
      protected void setText​(java.lang.CharSequence text)  
      protected void setView​(android.view.View view)  
      protected void show()  
      static boolean showedCustomToast​(java.lang.CharSequence message, int layoutResourceIdToCheckForMessage)
      Returns whether or not a particular custom Toast has been shown.
      static boolean showedToast​(java.lang.CharSequence message)
      query method that returns whether or not a particular Toast has been shown.
      static int shownToastCount()
      Returns the number of Toast requests that have been made during this test run or since reset() has been called.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ShadowToast

        public ShadowToast()
    • Method Detail

      • __constructor__

        @Implementation
        protected void __constructor__​(android.content.Context context)
      • makeText

        @Implementation
        protected static android.widget.Toast makeText​(android.content.Context context,
                                                       int resId,
                                                       int duration)
      • makeText

        @Implementation
        protected static android.widget.Toast makeText​(android.content.Context context,
                                                       java.lang.CharSequence text,
                                                       int duration)
      • show

        @Implementation
        protected void show()
      • setText

        @Implementation
        protected void setText​(int resId)
      • setText

        @Implementation
        protected void setText​(java.lang.CharSequence text)
      • setView

        @Implementation
        protected void setView​(android.view.View view)
      • getView

        @Implementation
        protected android.view.View getView()
      • setGravity

        @Implementation
        protected void setGravity​(int gravity,
                                  int xOffset,
                                  int yOffset)
      • getGravity

        @Implementation
        protected int getGravity()
      • getXOffset

        @Implementation
        protected int getXOffset()
      • getYOffset

        @Implementation
        protected int getYOffset()
      • setDuration

        @Implementation
        protected void setDuration​(int duration)
      • getDuration

        @Implementation
        protected int getDuration()
      • cancel

        @Implementation
        protected void cancel()
      • isCancelled

        public boolean isCancelled()
      • reset

        public static void reset()
        Discards the recorded Toasts. 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 of Toast requests that have been made during this test run or since reset() has been called.
        Returns:
        the number of Toast requests that have been made during this test run or since reset() has been called.
      • showedCustomToast

        public static boolean showedCustomToast​(java.lang.CharSequence message,
                                                int layoutResourceIdToCheckForMessage)
        Returns whether or not a particular custom Toast has been shown.
        Parameters:
        message - the message to search for
        layoutResourceIdToCheckForMessage - the id of the resource that contains the toast messages
        Returns:
        whether the Toast was requested
      • showedToast

        public static boolean showedToast​(java.lang.CharSequence message)
        query method that returns whether or not a particular Toast has been shown.
        Parameters:
        message - the message to search for
        Returns:
        whether the Toast was requested
      • getTextOfLatestToast

        public static java.lang.String getTextOfLatestToast()
        Returns the text of the most recently shown Toast.
        Returns:
        the text of the most recently shown Toast
      • getLatestToast

        public static android.widget.Toast getLatestToast()
        Returns the most recently shown Toast.
        Returns:
        the most recently shown Toast