package com.xtremelabs.robolectric.fakes;

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

@SuppressWarnings({"UnusedDeclaration"})
@Implements(PendingIntent.class)
public class ShadowPendingIntent {
    private Intent savedIntent;
    private boolean isServiceIntent;

    @Implementation
    public static PendingIntent getService(Context context, int requestCode, Intent intent, int flags) {
        PendingIntent pendingIntent = Robolectric.newInstanceOf(PendingIntent.class);
        ShadowPendingIntent fakePendingIntent = (ShadowPendingIntent) ProxyDelegatingHandler.getInstance().proxyFor(pendingIntent);
        fakePendingIntent.savedIntent = intent;
        fakePendingIntent.isServiceIntent = true;
        return pendingIntent;
    }

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

@@ -583,74 +583,365 @@
  get
-Service(Context context, int requestCode, Intent intent, int flags
+Activity(Context context, int requestCode, Intent intent, int flags) %7B%0A        return create(intent, false);%0A    %7D%0A%0A    @Implementation%0A    public static PendingIntent getService(Context context, int requestCode, Intent intent, int flags) %7B%0A        return create(intent, true);%0A    %7D%0A%0A    private static PendingIntent create(Intent intent, boolean isService
 ) %7B%0A
@@ -1250,19 +1250,24 @@
 ntent = 
-tru
+isServic
 e;%0A     
@@ -1432,16 +1432,17 @@
       if
+ 
 (isServi
@@ -1509,16 +1509,23 @@
        %7D
+ else %7B
 %0A       
@@ -1529,35 +1529,57 @@
     
-// else, will startActivity
+    context.startActivity(savedIntent);%0A        %7D
 %0A   

Support activity PendingIntents.