1 /* 2 * Copyright 2016, 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.provisioning; 18 19 import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE; 20 import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE; 21 import static org.junit.Assert.assertTrue; 22 23 import android.content.ComponentName; 24 import android.content.Context; 25 import android.support.test.InstrumentationRegistry; 26 import android.support.test.filters.SmallTest; 27 28 import com.android.managedprovisioning.model.ProvisioningParams; 29 30 import org.junit.Before; 31 import org.junit.Test; 32 import org.mockito.Mock; 33 import org.mockito.MockitoAnnotations; 34 35 /** 36 * Unit tests for {@link ProvisioningControllerFactory}. 37 */ 38 @SmallTest 39 public class ProvisioningControllerFactoryTest { 40 private static final ComponentName ADMIN = new ComponentName("com.test.admin", ".Receiver"); 41 private static final ProvisioningParams PROFILE_OWNER_PARAMS = new ProvisioningParams.Builder() 42 .setProvisioningAction(ACTION_PROVISION_MANAGED_PROFILE) 43 .setDeviceAdminComponentName(ADMIN) 44 .build(); 45 private static final ProvisioningParams DEVICE_OWNER_PARAMS = new ProvisioningParams.Builder() 46 .setProvisioningAction(ACTION_PROVISION_MANAGED_DEVICE) 47 .setDeviceAdminComponentName(ADMIN) 48 .build(); 49 50 private ProvisioningControllerFactory mFactory = new ProvisioningControllerFactory(); 51 @Mock private ProvisioningControllerCallback mCallback; 52 53 @Before 54 public void setUp() { 55 MockitoAnnotations.initMocks(this); 56 } 57 58 @Test 59 public void testProfileOwner() { 60 // WHEN calling the factory with a set of profile owner params 61 AbstractProvisioningController controller = 62 mFactory.createProvisioningController(InstrumentationRegistry.getTargetContext(), 63 PROFILE_OWNER_PARAMS, mCallback); 64 65 // THEN the controller should be a profile owner controller 66 assertTrue(controller instanceof ProfileOwnerProvisioningController); 67 } 68 69 @Test 70 public void testDeviceOwner() { 71 // WHEN calling the factory with a set of device owner params 72 AbstractProvisioningController controller = 73 mFactory.createProvisioningController(InstrumentationRegistry.getTargetContext(), 74 DEVICE_OWNER_PARAMS, mCallback); 75 76 // THEN the controller should be a device owner controller 77 assertTrue(controller instanceof DeviceOwnerProvisioningController); 78 } 79 } 80