Home | History | Annotate | Download | only in search
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  *
     16  */
     17 
     18 package com.android.settings.search;
     19 
     20 import static com.google.common.truth.Truth.assertThat;
     21 
     22 import android.content.Intent;
     23 import android.os.Parcel;
     24 
     25 import com.android.settings.testutils.SettingsRobolectricTestRunner;
     26 
     27 import org.junit.Test;
     28 import org.junit.runner.RunWith;
     29 
     30 @RunWith(SettingsRobolectricTestRunner.class)
     31 public class ResultPayloadTest {
     32 
     33     private static final String EXTRA_KEY = "key";
     34     private static final String EXTRA_VALUE = "value";
     35 
     36     @Test
     37     public void testParcelOrdering_StaysValid() {
     38         Intent intent = new Intent();
     39         intent.putExtra(EXTRA_KEY, EXTRA_VALUE);
     40         Parcel parcel = Parcel.obtain();
     41 
     42         final ResultPayload payload = new ResultPayload(intent);
     43         payload.writeToParcel(parcel, 0);
     44         // Reset parcel for reading
     45         parcel.setDataPosition(0);
     46         ResultPayload newPayload = ResultPayload.CREATOR.createFromParcel(parcel);
     47 
     48         String originalIntentExtra = payload.getIntent().getStringExtra(EXTRA_KEY);
     49         String copiedIntentExtra = newPayload.getIntent().getStringExtra(EXTRA_KEY);
     50         assertThat(originalIntentExtra).isEqualTo(copiedIntentExtra);
     51     }
     52 }
     53