Class ShadowToast

    • Constructor Detail

      • ShadowToast

        public ShadowToast()
    • Method Detail

      • setGravity

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

        @Implementation
        protected void setDuration​(int duration)
      • 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​(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​(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 String getTextOfLatestToast()
        Returns the text of the most recently shown Toast.
        Returns:
        the text of the most recently shown Toast
      • getLatestToast

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