1 /* 2 * Copyright (C) 2020 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.mediaroutertest; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertNotEquals; 21 22 import android.media.RoutingSessionInfo; 23 import android.support.test.filters.SmallTest; 24 import android.support.test.runner.AndroidJUnit4; 25 26 import org.junit.Test; 27 import org.junit.runner.RunWith; 28 29 /** 30 * Tests {@link RoutingSessionInfo} and its {@link RoutingSessionInfo.Builder builder}. 31 */ 32 @RunWith(AndroidJUnit4.class) 33 @SmallTest 34 public class RoutingSessionInfoTest { 35 public static final String TEST_ID = "test_id"; 36 public static final String TEST_CLIENT_PACKAGE_NAME = "com.test.client.package.name"; 37 public static final String TEST_NAME = "test_name"; 38 39 public static final String TEST_ROUTE_ID_0 = "test_route_type_0"; 40 public static final String TEST_ROUTE_ID_2 = "test_route_type_2"; 41 public static final String TEST_ROUTE_ID_4 = "test_route_type_4"; 42 public static final String TEST_ROUTE_ID_6 = "test_route_type_6"; 43 44 public static final String TEST_PROVIDER_ID = "test_provider_id"; 45 public static final String TEST_OTHER_PROVIDER_ID = "test_other_provider_id"; 46 47 // Tests if route IDs are changed properly according to provider ID. 48 @Test testProviderId()49 public void testProviderId() { 50 RoutingSessionInfo sessionInfo = new RoutingSessionInfo.Builder( 51 TEST_ID, TEST_CLIENT_PACKAGE_NAME) 52 .setName(TEST_NAME) 53 .addSelectedRoute(TEST_ROUTE_ID_0) 54 .addSelectableRoute(TEST_ROUTE_ID_2) 55 .addDeselectableRoute(TEST_ROUTE_ID_4) 56 .addTransferableRoute(TEST_ROUTE_ID_6) 57 .build(); 58 59 RoutingSessionInfo sessionInfoWithProviderId = new RoutingSessionInfo.Builder(sessionInfo) 60 .setProviderId(TEST_PROVIDER_ID).build(); 61 62 assertNotEquals(sessionInfo.getSelectedRoutes(), 63 sessionInfoWithProviderId.getSelectedRoutes()); 64 assertNotEquals(sessionInfo.getSelectableRoutes(), 65 sessionInfoWithProviderId.getSelectableRoutes()); 66 assertNotEquals(sessionInfo.getDeselectableRoutes(), 67 sessionInfoWithProviderId.getDeselectableRoutes()); 68 assertNotEquals(sessionInfo.getTransferableRoutes(), 69 sessionInfoWithProviderId.getTransferableRoutes()); 70 71 RoutingSessionInfo sessionInfoWithOtherProviderId = 72 new RoutingSessionInfo.Builder(sessionInfoWithProviderId) 73 .setProviderId(TEST_OTHER_PROVIDER_ID).build(); 74 75 assertNotEquals(sessionInfoWithOtherProviderId.getSelectedRoutes(), 76 sessionInfoWithProviderId.getSelectedRoutes()); 77 assertNotEquals(sessionInfoWithOtherProviderId.getSelectableRoutes(), 78 sessionInfoWithProviderId.getSelectableRoutes()); 79 assertNotEquals(sessionInfoWithOtherProviderId.getDeselectableRoutes(), 80 sessionInfoWithProviderId.getDeselectableRoutes()); 81 assertNotEquals(sessionInfoWithOtherProviderId.getTransferableRoutes(), 82 sessionInfoWithProviderId.getTransferableRoutes()); 83 84 RoutingSessionInfo sessionInfoWithProviderId2 = 85 new RoutingSessionInfo.Builder(sessionInfoWithProviderId).build(); 86 87 assertEquals(sessionInfoWithProviderId2.getSelectedRoutes(), 88 sessionInfoWithProviderId.getSelectedRoutes()); 89 assertEquals(sessionInfoWithProviderId2.getSelectableRoutes(), 90 sessionInfoWithProviderId.getSelectableRoutes()); 91 assertEquals(sessionInfoWithProviderId2.getDeselectableRoutes(), 92 sessionInfoWithProviderId.getDeselectableRoutes()); 93 assertEquals(sessionInfoWithProviderId2.getTransferableRoutes(), 94 sessionInfoWithProviderId.getTransferableRoutes()); 95 } 96 } 97