Home | History | Annotate | Download | only in shadows
      1 package com.xtremelabs.robolectric.shadows;
      2 
      3 import android.os.Bundle;
      4 import android.os.Handler;
      5 import android.os.ResultReceiver;
      6 import com.xtremelabs.robolectric.WithTestDefaultsRunner;
      7 import org.junit.Test;
      8 import org.junit.runner.RunWith;
      9 
     10 import static org.junit.Assert.assertEquals;
     11 
     12 @RunWith(WithTestDefaultsRunner.class)
     13 public class ResultReceiverTest {
     14     @Test
     15     public void callingSend_shouldCallOverridenOnReceiveResultWithTheSameArguments() throws Exception {
     16         TestResultReceiver testResultReceiver = new TestResultReceiver(null);
     17         Bundle bundle = new Bundle();
     18 
     19         testResultReceiver.send(5, bundle);
     20         assertEquals(5, testResultReceiver.resultCode);
     21         assertEquals(bundle, testResultReceiver.resultData);
     22     }
     23 
     24     static class TestResultReceiver extends ResultReceiver {
     25         int resultCode;
     26         Bundle resultData;
     27 
     28         public TestResultReceiver(Handler handler) {
     29             super(handler);
     30         }
     31 
     32         @Override
     33         protected void onReceiveResult(int resultCode, Bundle resultData) {
     34             this.resultCode = resultCode;
     35             this.resultData = resultData;
     36         }
     37     }
     38 }
     39