1 /* <lambda>null2 * Copyright 2025 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 androidx.compose.foundation.text.test 18 19 import com.google.common.truth.Fact.simpleFact 20 import com.google.common.truth.FailureMetadata 21 import com.google.common.truth.Subject 22 import com.google.common.truth.Truth.assertAbout 23 import kotlinx.coroutines.Job 24 25 internal fun assertThatJob(job: Job?): JobSubject = 26 assertAbout(JobSubject.SUBJECT_FACTORY).that(job)!! 27 28 internal class JobSubject 29 private constructor(failureMetadata: FailureMetadata?, private val subject: Job?) : 30 Subject(failureMetadata, subject) { 31 companion object { 32 val SUBJECT_FACTORY: Factory<JobSubject?, Job?> = Factory { failureMetadata, subject -> 33 JobSubject(failureMetadata, subject) 34 } 35 } 36 37 private val nullCheckedSubject: Job 38 get() { 39 if (subject == null) failWithoutActual(simpleFact("is null")) 40 return subject!! 41 } 42 43 fun isActive() { 44 check("isActive").that(nullCheckedSubject.isActive).isTrue() 45 } 46 47 /** Checks that the job is completed regardless of whether it was cancelled. */ 48 fun isCompleted() { 49 check("isCompleted").that(nullCheckedSubject.isCompleted).isTrue() 50 } 51 52 /** Checks that the job is completed and not cancelled. */ 53 fun isCompletedSuccessfully() { 54 check("isCompleted").that(nullCheckedSubject.isCompleted).isTrue() 55 check("isCancelled").that(nullCheckedSubject.isCancelled).isFalse() 56 } 57 58 fun isCancelled() { 59 check("isCancelled").that(nullCheckedSubject.isCancelled).isTrue() 60 } 61 } 62