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 com.android.bedstead.nene.services 18 19 import com.android.bedstead.nene.TestApis 20 import com.android.bedstead.nene.exceptions.NeneException 21 import com.google.common.truth.Truth.assertThat 22 import org.junit.Assert.assertThrows 23 import org.junit.Test 24 import org.junit.runner.RunWith 25 import org.junit.runners.JUnit4 26 27 @RunWith(JUnit4::class) 28 class ServicesTest { 29 30 @Test availableService_serviceIsAvailable_returnsTruenull31 fun availableService_serviceIsAvailable_returnsTrue() { 32 assertThat(TestApis.services().serviceIsAvailable(AVAILABLE_SERVICE)).isTrue(); 33 } 34 35 @Test unavailableService_serviceIsAvailable_throwsnull36 fun unavailableService_serviceIsAvailable_throws() { 37 val exception = assertThrows(NeneException::class.java) { 38 TestApis.services().serviceIsAvailable(UNAVAILABLE_SERVICE) 39 } 40 assertThat(exception).hasMessageThat().contains("Unknown service $UNAVAILABLE_SERVICE") 41 } 42 43 @Test hiddenService_serviceIsAvailable_throwsnull44 fun hiddenService_serviceIsAvailable_throws() { 45 val exception = assertThrows(NeneException::class.java) { 46 TestApis.services().serviceIsAvailable(HIDDEN_SERVICE) 47 } 48 assertThat(exception).hasMessageThat().contains("Unable to get service $HIDDEN_SERVICE") 49 } 50 51 private companion object { 52 /** See [Context.DEVICE_POLICY_SERVICE]. */ 53 private const val AVAILABLE_SERVICE = "device_policy" 54 /** See [Context.ACTIVITY_TASK_SERVICE]. */ 55 private const val UNAVAILABLE_SERVICE = "activity_task" 56 /** See [Context.CREDENTIAL_SERVICE]. */ 57 private const val HIDDEN_SERVICE = "credential" 58 } 59 60 }