Home | History | Annotate | Download | only in testing
      1 /*
      2  * Copyright (C) 2016 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 package com.android.documentsui.testing;
     17 
     18 import static android.content.Intent.EXTRA_INTENT;
     19 import static junit.framework.Assert.assertNotNull;
     20 import static junit.framework.Assert.assertTrue;
     21 import static org.junit.Assert.assertEquals;
     22 
     23 import android.content.Intent;
     24 import android.net.Uri;
     25 import android.os.Parcelable;
     26 
     27 import junit.framework.Assert;
     28 
     29 import java.util.ArrayList;
     30 import java.util.List;
     31 
     32 /**
     33  * Handy-dandy Junit asserts covering Intents.
     34  */
     35 public final class IntentAsserts {
     36 
     37     private IntentAsserts() {}
     38 
     39     public static void assertHasAction(Intent intent, String expected) {
     40         assertEquals(expected, intent.getAction());
     41     }
     42 
     43     public static Intent assertHasExtraIntent(Intent intent) {
     44         Intent extra = (Intent) intent.getExtra(EXTRA_INTENT);
     45         assertNotNull(extra);
     46         return extra;
     47     }
     48 
     49     public static Uri assertHasExtraUri(Intent intent, String key) {
     50         Object value = intent.getExtra(key);
     51         assertNotNull(value);
     52         assertTrue(value instanceof Uri);
     53         return (Uri) value;
     54     }
     55 
     56     public static List<Parcelable> assertHasExtraList(Intent intent, String key) {
     57         ArrayList<Parcelable> list = intent.getParcelableArrayListExtra(key);
     58         assertNotNull(list);
     59         return list;
     60     }
     61 
     62     public static List<Parcelable> assertHasExtraList(Intent intent, String key, int size) {
     63         List<Parcelable> list = assertHasExtraList(intent, key);
     64         Assert.assertEquals(size, list.size());
     65         return list;
     66     }
     67 }
     68