1 /* 2 * Copyright 2017, 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.managedprovisioning.manageduser; 18 19 import static org.mockito.Mockito.verify; 20 import static org.mockito.Mockito.verifyZeroInteractions; 21 22 import android.os.UserHandle; 23 24 import androidx.test.filters.SmallTest; 25 26 import com.android.managedprovisioning.task.nonrequiredapps.SystemAppsSnapshot; 27 28 import org.junit.Before; 29 import org.junit.Test; 30 import org.mockito.Mock; 31 import org.mockito.MockitoAnnotations; 32 33 /** 34 * Unit tests for {@link ManagedUserCreationController}. 35 */ 36 @SmallTest 37 public class ManagedUserCreationControllerTest { 38 39 private static final int MANAGED_USER_USER_ID = 12; 40 41 @Mock 42 private SystemAppsSnapshot mSystemAppsSnapshot; 43 44 @Before setUp()45 public void setUp() { 46 MockitoAnnotations.initMocks(this); 47 } 48 49 @Test testNullUserId()50 public void testNullUserId() { 51 ManagedUserCreationController controller = new ManagedUserCreationController( 52 UserHandle.USER_NULL, false, mSystemAppsSnapshot); 53 54 controller.run(); 55 56 verifyZeroInteractions(mSystemAppsSnapshot); 57 } 58 59 @Test testLeaveAllSystemApps()60 public void testLeaveAllSystemApps() { 61 ManagedUserCreationController controller = new ManagedUserCreationController( 62 MANAGED_USER_USER_ID, true, mSystemAppsSnapshot); 63 64 controller.run(); 65 66 verifyZeroInteractions(mSystemAppsSnapshot); 67 } 68 69 @Test testTakeSnapshot()70 public void testTakeSnapshot() { 71 ManagedUserCreationController controller = new ManagedUserCreationController( 72 MANAGED_USER_USER_ID, false, mSystemAppsSnapshot); 73 74 controller.run(); 75 76 verify(mSystemAppsSnapshot).takeNewSnapshot(MANAGED_USER_USER_ID); 77 } 78 } 79