package com.xtremelabs.robolectric.fakes;

import android.content.Context;
import android.widget.Toast;
import com.xtremelabs.robolectric.ProxyDelegatingHandler;
import com.xtremelabs.robolectric.util.Implementation;
import com.xtremelabs.robolectric.util.Implements;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@SuppressWarnings({"UnusedDeclaration"})
@Implements(Toast.class)
public class FakeToast {
    private static Map<CharSequence, Toast> toasts = new HashMap<CharSequence, Toast>();

    private boolean wasShown = false;

    @Implementation
    public static Toast makeText(Context context, int resId, int duration) {
        return makeText(context, context.getResources().getString(resId), duration);
    }

    @Implementation
    public static Toast makeText(Context context, CharSequence text, int duration) {
        Toast toast = new Toast(null);
        toasts.put(text, toast);
        return toast;
    }

    public static boolean showedToast(CharSequence message) {
        return toasts.containsKey(message) && proxyFor(toasts.get(message)).wasShown;
    }

    private static FakeToast proxyFor(Toast toast) {
        return (FakeToast) ProxyDelegatingHandler.getInstance().proxyFor(toast);
    }

    public static void reset() {
        toasts.clear();
    }

    @Implementation
    public void show() {
        wasShown = true;
    }

    public static Set<String> showedToasts() {
        HashSet<String> strings = new HashSet<String>();
        for (CharSequence toastString : toasts.keySet()) {
            if (proxyFor(toasts.get(toastString.toString())).wasShown) {
                strings.add(toastString.toString());
            }
        }
        return strings;
    }
}

@@ -538,16 +538,60 @@
 oast%3E();
+%0A    private static int shownToastCount = 0;
 %0A%0A    pr
@@ -1010,32 +1010,136 @@
 n toast;%0A    %7D%0A%0A
+    @Implementation%0A    public void show() %7B%0A        wasShown = true;%0A        shownToastCount++;%0A    %7D%0A%0A
     public stati
@@ -1148,26 +1148,25 @@
 boolean show
-ed
+n
 Toast(CharSe
@@ -1482,79 +1482,112 @@
     
-%7D%0A%0A
     
-@Implementation%0A    public void show() %7B%0A        wasShown = true
+shownToastCount = 0;%0A    %7D%0A%0A    public static int shownToastCount() %7B%0A        return shownToastCount
 ;%0A  
@@ -1625,18 +1625,17 @@
 ng%3E show
-ed
+n
 Toasts()

Make FakeToast count show() invocations and change "showed" to "shown"