1 package com.xtremelabs.robolectric.shadows; 2 3 import android.os.Bundle; 4 import android.os.ResultReceiver; 5 import com.xtremelabs.robolectric.internal.Implementation; 6 import com.xtremelabs.robolectric.internal.Implements; 7 import com.xtremelabs.robolectric.internal.RealObject; 8 9 import java.lang.reflect.InvocationTargetException; 10 import java.lang.reflect.Method; 11 12 @Implements(ResultReceiver.class) 13 public class ShadowResultReceiver { 14 // TODO: Use handler to make asynchronous 15 16 @RealObject private ResultReceiver realResultReceiver; 17 18 @Implementation 19 public void send(int resultCode, android.os.Bundle resultData) { 20 try { 21 Method onReceiveResult = ResultReceiver.class.getDeclaredMethod("onReceiveResult", Integer.TYPE, Bundle.class); 22 onReceiveResult.setAccessible(true); 23 onReceiveResult.invoke(realResultReceiver, resultCode, resultData); 24 } catch (NoSuchMethodException e) { 25 throw new RuntimeException(e); 26 } catch (InvocationTargetException e) { 27 throw new RuntimeException(e); 28 } catch (IllegalAccessException e) { 29 throw new RuntimeException(e); 30 } 31 } 32 } 33