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