1 /* 2 * Copyright 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 17 package com.android.managedprovisioning.task; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertTrue; 21 22 import android.content.pm.PackageManager; 23 24 import androidx.test.filters.SmallTest; 25 26 import com.android.managedprovisioning.task.CrossProfileIntentFilter.Direction; 27 28 import org.junit.Test; 29 30 /** 31 * Unit tests for {@link CrossProfileIntentFilter}. 32 */ 33 @SmallTest 34 public class CrossProfileIntentFilterTest { 35 36 private static final int TEST_FLAGS = PackageManager.SKIP_CURRENT_PROFILE; 37 private static final int TEST_DIRECTION = Direction.TO_PARENT; 38 private static final boolean TEST_LETSDATAINTOPROFILE = true; 39 private static final String ACTION_1 = "action1"; 40 private static final String ACTION_2 = "action2"; 41 private static final String CATEGORY_1 = "category1"; 42 private static final String CATEGORY_2 = "category2"; 43 private static final String SCHEME_1 = "scheme1"; 44 private static final String SCHEME_2 = "scheme2"; 45 private static final String TYPE_1 = "*/*"; 46 private static final String TYPE_2 = "com.test/*"; 47 48 @Test testBuilder()49 public void testBuilder() { 50 CrossProfileIntentFilter filter = 51 new CrossProfileIntentFilter.Builder(TEST_DIRECTION, TEST_FLAGS, 52 TEST_LETSDATAINTOPROFILE) 53 .addAction(ACTION_1) 54 .addAction(ACTION_2) 55 .addCategory(CATEGORY_1) 56 .addCategory(CATEGORY_2) 57 .addDataScheme(SCHEME_1) 58 .addDataScheme(SCHEME_2) 59 .addDataType(TYPE_1) 60 .addDataType(TYPE_2) 61 .build(); 62 63 assertEquals(TEST_DIRECTION, filter.direction); 64 assertEquals(TEST_FLAGS, filter.flags); 65 assertEquals(TEST_LETSDATAINTOPROFILE, filter.letsPersonalDataIntoProfile); 66 67 assertEquals(ACTION_1, filter.filter.getAction(0)); 68 assertEquals(ACTION_2, filter.filter.getAction(1)); 69 assertEquals(CATEGORY_1, filter.filter.getCategory(0)); 70 assertEquals(CATEGORY_2, filter.filter.getCategory(1)); 71 assertEquals(SCHEME_1, filter.filter.getDataScheme(0)); 72 assertEquals(SCHEME_2, filter.filter.getDataScheme(1)); 73 assertTrue(filter.filter.hasDataType(TYPE_1)); 74 assertTrue(filter.filter.hasDataType(TYPE_2)); 75 } 76 } 77