package com.xtremelabs.robolectric.shadows;

import android.app.Application;
import android.app.Service;
import android.content.Context;
import android.content.ServiceConnection;

import com.xtremelabs.robolectric.Robolectric;
import com.xtremelabs.robolectric.internal.Implementation;
import com.xtremelabs.robolectric.internal.Implements;
import com.xtremelabs.robolectric.internal.RealObject;

import static com.xtremelabs.robolectric.Robolectric.shadowOf;

@SuppressWarnings({"UnusedDeclaration"})
@Implements(Service.class)
public class ShadowService extends ShadowContextWrapper {
    @RealObject Service realService;
    
    private boolean unbindServiceShouldThrowIllegalArgument = false;

    @Implementation
    public final Application getApplication() {
        return Robolectric.application;
    }

    @Implementation @Override
    public Context getApplicationContext() {
        return Robolectric.application;
    }

    @Implementation
    public void onDestroy() {
        assertNoBroadcastListenersRegistered();
    }
    
    @Implementation 
    public void unbindService(ServiceConnection conn) {
    	if (unbindServiceShouldThrowIllegalArgument) {
    		throw new IllegalArgumentException();
    	}
    }
    
    public void setUnbindServiceShouldThrowIllegalArgument(boolean flag) {
    	unbindServiceShouldThrowIllegalArgument = flag;
    }

    /**
     * Utility method that throws a {@code RuntimeException} if any {@code BroadcastListener}s are still registered.
     */
    public void assertNoBroadcastListenersRegistered() {
        ((ShadowApplication) shadowOf(getApplicationContext())).assertNoBroadcastListenersRegistered(realService, "Service");
    }
}

@@ -618,24 +618,70 @@
 rvice;%0A    %0A
+    private boolean selfStopped = false;%0A    %0A
     private 
@@ -737,16 +737,16 @@
  false;%0A
-
 %0A    @Im
@@ -1271,24 +1271,109 @@
 %0A    %7D%0A    %0A
+    @Implementation%0A    public void stopSelf() %7B%0A    %09selfStopped = true;%0A    %7D%0A    %0A
     public v
@@ -1681,24 +1681,24 @@
 istered() %7B%0A
-
         ((Sh
@@ -1817,10 +1817,168 @@
 ;%0A    %7D%0A
+    %0A    /**%0A     * Non-Android accessor, to use in assertions. %0A     * @return%0A     */%0A    public boolean isStoppedBySelf() %7B%0A    %09return selfStopped;%0A    %7D%0A
 %7D%0A

Add a means to check for Service#svtopSelf being invoked