1 /* <lambda>null2 * Copyright (C) 2023 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.systemui.qs.tiles.impl.custom 18 19 import android.service.quicksettings.Tile 20 import com.android.systemui.qs.tiles.impl.custom.TileSubject.Companion.assertThat 21 import com.android.systemui.qs.tiles.impl.custom.TileSubject.Companion.tiles 22 import com.google.common.truth.FailureMetadata 23 import com.google.common.truth.Subject 24 import com.google.common.truth.Subject.Factory 25 import com.google.common.truth.Truth 26 27 /** 28 * [Tile]-specific extension for [Truth]. Use [assertThat] or [tiles] to get an instance of this 29 * subject. 30 */ 31 class TileSubject private constructor(failureMetadata: FailureMetadata, subject: Tile?) : 32 Subject(failureMetadata, subject) { 33 34 private val actual: Tile? = subject 35 36 /** Asserts if the [Tile] fields are the same. */ 37 fun isEqualTo(other: Tile?) { 38 if (actual == null) { 39 check("other").that(other).isNull() 40 return 41 } else { 42 check("other").that(other).isNotNull() 43 other ?: return 44 } 45 46 check("icon").that(actual.icon).isEqualTo(other.icon) 47 check("label").that(actual.label).isEqualTo(other.label) 48 check("subtitle").that(actual.subtitle).isEqualTo(other.subtitle) 49 check("contentDescription") 50 .that(actual.contentDescription) 51 .isEqualTo(other.contentDescription) 52 check("stateDescription").that(actual.stateDescription).isEqualTo(other.stateDescription) 53 check("activityLaunchForClick") 54 .that(actual.activityLaunchForClick) 55 .isEqualTo(other.activityLaunchForClick) 56 check("state").that(actual.state).isEqualTo(other.state) 57 } 58 59 companion object { 60 61 /** Returns a factory to be used with [Truth.assertAbout]. */ 62 fun tiles(): Factory<TileSubject, Tile?> { 63 return Factory { failureMetadata: FailureMetadata, subject: Tile? -> 64 TileSubject(failureMetadata, subject) 65 } 66 } 67 68 /** Shortcut for `Truth.assertAbout(tiles()).that(tile)`. */ 69 fun assertThat(tile: Tile?): TileSubject = Truth.assertAbout(tiles()).that(tile) 70 } 71 } 72