Home | History | Annotate | Download | only in selection
      1 /*
      2  * Copyright 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 package androidx.recyclerview.selection;
     18 
     19 import static org.junit.Assert.assertEquals;
     20 
     21 import android.net.Uri;
     22 import android.os.Bundle;
     23 import android.support.test.filters.SmallTest;
     24 import android.support.test.runner.AndroidJUnit4;
     25 
     26 import androidx.recyclerview.selection.testing.Bundles;
     27 
     28 import org.junit.Before;
     29 import org.junit.Test;
     30 import org.junit.runner.RunWith;
     31 
     32 import java.util.ArrayList;
     33 import java.util.List;
     34 
     35 @RunWith(AndroidJUnit4.class)
     36 @SmallTest
     37 public final class StorageStrategy_ParcelableTest {
     38 
     39     private static final List<Uri> sData;
     40     static {
     41         sData = new ArrayList<>(5);
     42         sData.add(Uri.parse("content://cheese0"));
     43         sData.add(Uri.parse("content://cheese1"));
     44         sData.add(Uri.parse("content://cheese2"));
     45         sData.add(Uri.parse("content://cheese3"));
     46         sData.add(Uri.parse("content://cheese4"));
     47     }
     48 
     49     private StorageStrategy<Uri> mStorage;
     50 
     51     @Before
     52     public void setUp() {
     53         mStorage = StorageStrategy.createParcelableStorage(Uri.class);
     54     }
     55 
     56     @Test
     57     public void testReadWrite() {
     58 
     59         MutableSelection<Uri> orig = new MutableSelection<>();
     60         orig.add(sData.get(2));
     61         orig.add(sData.get(3));
     62         orig.add(sData.get(4));
     63 
     64         Bundle parceled = Bundles.forceParceling(mStorage.asBundle(orig));
     65         Selection<Uri> restored = mStorage.asSelection(parceled);
     66 
     67         assertEquals(orig, restored);
     68     }
     69 }
     70