Created
February 11, 2018 17:09
-
-
Save mcassiano/1e3110af3bbaa77e2e0b73b22af990d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IdlingToaster extends Toaster { | |
private HashSet<Toast> toasts = new HashSet<>(); | |
@Override | |
public Toast makeText(Context context, CharSequence text, int duration) { | |
Toast toast = Toast.makeText(context, text, LENGTH_SHORT); | |
toast.getView().addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() { | |
@Override | |
public void onViewAttachedToWindow(View view) { | |
toasts.add(toast); | |
} | |
@Override | |
public void onViewDetachedFromWindow(View view) { | |
toasts.remove(toast); | |
} | |
}); | |
return toast; | |
} | |
public void cancel() { | |
for (Toast t : toasts) | |
t.cancel(); | |
toasts.clear(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void render_shouldShowCurrentPlace() throws InterruptedException { | |
// do your setup | |
toaster.cancel(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Toaster { | |
public Toast makeText(Context context, CharSequence text, int duration) { | |
return Toast.makeText(context, text, duration); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment