1 /* 2 * Copyright (C) 2022 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.remoteaccountauthenticator; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import com.android.bedstead.harrier.BedsteadJUnit4; 22 import com.android.bedstead.harrier.DeviceState; 23 import com.android.bedstead.harrier.annotations.EnsureHasAdditionalUser; 24 import com.android.bedstead.nene.accounts.AccountReference; 25 26 import org.junit.ClassRule; 27 import org.junit.Rule; 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 31 @RunWith(BedsteadJUnit4.class) 32 public final class RemoteAccountAuthenticatorTest { 33 34 @ClassRule @Rule 35 public static final DeviceState sDeviceState = new DeviceState(); 36 37 @Test install_appIsInstalled()38 public void install_appIsInstalled() { 39 try (RemoteAccountAuthenticator authenticator = RemoteAccountAuthenticator.install()) { 40 assertThat(authenticator.testApp().pkg().installedOnUser()).isTrue(); 41 } 42 } 43 44 @Test 45 @EnsureHasAdditionalUser install_differentUser_appIsInstalled()46 public void install_differentUser_appIsInstalled() { 47 try (RemoteAccountAuthenticator authenticator = 48 RemoteAccountAuthenticator.install(sDeviceState.additionalUser())) { 49 assertThat(authenticator.testApp().pkg().installedOnUser( 50 sDeviceState.additionalUser())).isTrue(); 51 } 52 } 53 54 @Test autoclose_appIsUninstalled()55 public void autoclose_appIsUninstalled() { 56 RemoteAccountAuthenticator authenticator = RemoteAccountAuthenticator.install(); 57 try (authenticator) { 58 // Just using autoclose 59 } 60 61 assertThat(authenticator.testApp().pkg().installedOnUser()).isFalse(); 62 } 63 64 @Test addAccount_accountIsAdded()65 public void addAccount_accountIsAdded() throws Exception { 66 try (RemoteAccountAuthenticator authenticator = 67 RemoteAccountAuthenticator.install()) { 68 AccountReference account = authenticator.addAccount().add(); 69 70 assertThat(authenticator.allAccounts()).contains(account); 71 } 72 } 73 74 @Test remove_accountIsRemoved()75 public void remove_accountIsRemoved() throws Exception { 76 try (RemoteAccountAuthenticator authenticator = 77 RemoteAccountAuthenticator.install()) { 78 AccountReference account = authenticator.addAccount().add(); 79 account.remove(); 80 81 assertThat(authenticator.allAccounts()).doesNotContain(account); 82 } 83 } 84 85 @Test accountAutoclose_accountIsRemoved()86 public void accountAutoclose_accountIsRemoved() throws Exception { 87 try (RemoteAccountAuthenticator authenticator = 88 RemoteAccountAuthenticator.install()) { 89 AccountReference account = authenticator.addAccount().add(); 90 try (account) { 91 // Just using autoclose 92 } 93 94 assertThat(authenticator.allAccounts()).doesNotContain(account); 95 } 96 } 97 } 98