1 /* 2 * Copyright (C) 2022 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 android.net; 18 19 import static com.android.testutils.DevSdkIgnoreRuleKt.SC_V2; 20 import static com.android.testutils.ParcelUtils.assertParcelingIsLossless; 21 22 import static org.junit.Assert.assertThrows; 23 24 import com.android.testutils.DevSdkIgnoreRule; 25 import com.android.testutils.DevSdkIgnoreRunner; 26 27 import org.junit.Test; 28 import org.junit.runner.RunWith; 29 30 @RunWith(DevSdkIgnoreRunner.class) 31 @DevSdkIgnoreRule.IgnoreUpTo(SC_V2) 32 public class EthernetNetworkUpdateRequestTest { buildIpConfiguration()33 private IpConfiguration buildIpConfiguration() { 34 return new IpConfiguration.Builder().setHttpProxy( 35 new ProxyInfo("test.example.com", 1234, "")).build(); 36 } 37 buildNetworkCapabilities()38 private NetworkCapabilities buildNetworkCapabilities() { 39 return new NetworkCapabilities.Builder().addTransportType( 40 NetworkCapabilities.TRANSPORT_ETHERNET).build(); 41 } 42 43 @Test testParcelUnparcel()44 public void testParcelUnparcel() { 45 EthernetNetworkUpdateRequest reqWithNonNull = 46 new EthernetNetworkUpdateRequest.Builder().setIpConfiguration( 47 buildIpConfiguration()).setNetworkCapabilities( 48 buildNetworkCapabilities()).build(); 49 EthernetNetworkUpdateRequest reqWithNullCaps = 50 new EthernetNetworkUpdateRequest.Builder().setIpConfiguration( 51 buildIpConfiguration()).build(); 52 EthernetNetworkUpdateRequest reqWithNullConfig = 53 new EthernetNetworkUpdateRequest.Builder().setNetworkCapabilities( 54 buildNetworkCapabilities()).build(); 55 56 assertParcelingIsLossless(reqWithNonNull); 57 assertParcelingIsLossless(reqWithNullCaps); 58 assertParcelingIsLossless(reqWithNullConfig); 59 } 60 61 @Test testEmptyUpdateRequestThrows()62 public void testEmptyUpdateRequestThrows() { 63 EthernetNetworkUpdateRequest.Builder emptyBuilder = 64 new EthernetNetworkUpdateRequest.Builder(); 65 assertThrows(IllegalStateException.class, () -> emptyBuilder.build()); 66 } 67 } 68