1 /* 2 * Copyright (C) 2024 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.app.sdksandbox; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.os.Bundle; 22 import android.os.Parcel; 23 24 import org.junit.Test; 25 import org.junit.runner.RunWith; 26 import org.junit.runners.JUnit4; 27 28 @RunWith(JUnit4.class) 29 public class LoadSdkExceptionUnitTest { 30 @Test testLoadSdkExceptionWriteToParcel()31 public void testLoadSdkExceptionWriteToParcel() { 32 Bundle bundle = new Bundle(); 33 bundle.putChar("testKey", /*testValue=*/ 'C'); 34 Exception cause = new Exception(/*errorMessage=*/ "Error Message"); 35 36 LoadSdkException exception = new LoadSdkException(cause, bundle); 37 38 Parcel parcel = Parcel.obtain(); 39 exception.writeToParcel(parcel, /*flags=*/ 0); 40 41 // Create LoadSdkException with the same parcel 42 parcel.setDataPosition(0); // rewind 43 LoadSdkException exceptionCheck = LoadSdkException.CREATOR.createFromParcel(parcel); 44 45 assertThat(exceptionCheck.getLoadSdkErrorCode()).isEqualTo(exception.getLoadSdkErrorCode()); 46 assertThat(exceptionCheck.getMessage()).isEqualTo(exception.getMessage()); 47 assertThat(exceptionCheck.getExtraInformation().getChar("testKey")) 48 .isEqualTo(exception.getExtraInformation().getChar("testKey")); 49 assertThat(exceptionCheck.getExtraInformation().keySet()).containsExactly("testKey"); 50 } 51 52 @Test testLoadSdkExceptionDescribeContents()53 public void testLoadSdkExceptionDescribeContents() throws Exception { 54 LoadSdkException exception = new LoadSdkException(new Exception(), new Bundle()); 55 assertThat(exception.describeContents()).isEqualTo(0); 56 } 57 } 58