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.service.settings.preferences 18 19 import android.os.Parcel 20 import android.platform.test.annotations.RequiresFlagsEnabled 21 import android.platform.test.flag.junit.CheckFlagsRule 22 import android.platform.test.flag.junit.DeviceFlagsValueProvider 23 import androidx.test.ext.junit.runners.AndroidJUnit4 24 import androidx.test.filters.SmallTest 25 import com.android.settingslib.flags.Flags.FLAG_SETTINGS_CATALYST 26 import com.google.common.truth.Truth.assertThat 27 import org.junit.Rule 28 import org.junit.Test 29 import org.junit.runner.RunWith 30 31 @RunWith(AndroidJUnit4::class) 32 @SmallTest 33 @RequiresFlagsEnabled(FLAG_SETTINGS_CATALYST) 34 class SetValueResultTest { 35 36 @get:Rule 37 val checkFlagsRule: CheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule() 38 39 @Test buildSetValueResult_allFieldsSetnull40 fun buildSetValueResult_allFieldsSet() { 41 val req = SetValueResult.Builder(SetValueResult.RESULT_DISABLED).build() 42 43 assertThat(req.resultCode).isEqualTo(SetValueResult.RESULT_DISABLED) 44 } 45 46 @Test buildSetValueResult_fromParcelablenull47 fun buildSetValueResult_fromParcelable() { 48 val old = SetValueResult.Builder(SetValueResult.RESULT_DISABLED).build() 49 50 val parcel = Parcel.obtain() 51 old.writeToParcel(parcel, 0) 52 parcel.setDataPosition(0) 53 val new = SetValueResult.CREATOR.createFromParcel(parcel) 54 55 assertThat(new.resultCode).isEqualTo(SetValueResult.RESULT_DISABLED) 56 } 57 } 58