package com.xtremelabs.robolectric.shadows;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import com.xtremelabs.robolectric.Robolectric;
import com.xtremelabs.robolectric.internal.Implementation;
import com.xtremelabs.robolectric.internal.Implements;

/**
 * Shadow of {@code PendingIntent} that creates and sends {@code Intent}s appropriately.
 */
@SuppressWarnings({"UnusedDeclaration"})
@Implements(PendingIntent.class)
public class ShadowPendingIntent {
    private Intent savedIntent;
    private boolean isServiceIntent;

    @Implementation
    public static PendingIntent getActivity(Context context, int requestCode, Intent intent, int flags) {
        return create(intent, false);
    }

    @Implementation
    public static PendingIntent getService(Context context, int requestCode, Intent intent, int flags) {
        return create(intent, true);
    }

    @Implementation
    public void send(Context context, int code, Intent intent) throws PendingIntent.CanceledException {
        if (isServiceIntent) {
            context.startService(savedIntent);
        } else {
            context.startActivity(savedIntent);
        }
    }

    private static PendingIntent create(Intent intent, boolean isService) {
        PendingIntent pendingIntent = Robolectric.newInstanceOf(PendingIntent.class);
        ShadowPendingIntent shadowPendingIntent = (ShadowPendingIntent) Robolectric.shadowOf_(pendingIntent);
        shadowPendingIntent.savedIntent = intent;
        shadowPendingIntent.isServiceIntent = isService;
        return pendingIntent;
    }
}

@@ -531,24 +531,58 @@
 avedIntent;%0A
+    private Context savedContext;%0A
     private 
@@ -606,16 +606,16 @@
 Intent;%0A
-
 %0A    @Im
@@ -747,32 +747,41 @@
   return create(
+context, 
 intent, false);%0A
@@ -934,16 +934,25 @@
  create(
+context, 
 intent, 
@@ -955,32 +955,168 @@
 nt, true);%0A    %7D
+%0A    %0A    @Implementation%0A    public void send() throws PendingIntent.CanceledException %7B%0A    %09send(savedContext, 0, savedIntent);%0A    %7D
 %0A%0A    @Implement
@@ -1380,24 +1380,28 @@
     %7D%0A    %7D%0A
+    
 %0A    private
@@ -1429,16 +1429,33 @@
  create(
+Context context, 
 Intent i
@@ -1724,24 +1724,24 @@
 t = intent;%0A
-
         shad
@@ -1785,16 +1785,68 @@
 ervice;%0A
+        shadowPendingIntent.savedContext = context;%0A
         

Add no-params form of #send()