Source:
public void init() throws Exception { DeviceConfigurationManager.getInstance().initConfig(); log.info("Initializing"); for (int i = 0; i < NO_OF_DEVICES; i++) { deviceIds.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE)); } List<Device> devices = TestDataHolder.generateDummyDeviceData(this.deviceIds); DeviceManagementProviderService deviceMgtService = new DeviceManagementProviderServiceImpl(); DeviceManagementServiceComponent.notifyStartupListeners(); DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService); DeviceManagementDataHolder.getInstance().setRegistryService(getRegistryService()); DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(new GroupManagementProviderServiceImpl()); DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null); deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)); for (Device device : devices) { deviceMgtService.enrollDevice(device); } List<Device> returnedDevices = deviceMgtService.getAllDevices(DEVICE_TYPE); for (Device device : returnedDevices) { if (!device.getDeviceIdentifier().startsWith(DEVICE_ID_PREFIX)) { throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!"); } } deviceAccessAuthorizationService = Mockito.mock(DeviceAccessAuthorizationServiceImpl.class, Mockito.CALLS_REAL_METHODS); defaultUserClaims = buildDefaultUserClaims(FIRST_NAME, LAST_NAME, EMAIL); initializeTestEnvironment(); }

Target:
public void init() throws Exception { DeviceConfigurationManager.getInstance().initConfig(); log.info("Initializing test environment to test DeviceAccessAuthorization Class"); for (int i = 0; i < NO_OF_DEVICES; i++) { deviceIds.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE)); } List<Device> devices = TestDataHolder.generateDummyDeviceData(this.deviceIds); DeviceManagementProviderService deviceMgtService = new DeviceManagementProviderServiceImpl(); DeviceManagementServiceComponent.notifyStartupListeners(); DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService); DeviceManagementDataHolder.getInstance().setRegistryService(getRegistryService()); DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(new GroupManagementProviderServiceImpl()); DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null); deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)); for (Device device : devices) { deviceMgtService.enrollDevice(device); } List<Device> returnedDevices = deviceMgtService.getAllDevices(DEVICE_TYPE); for (Device device : returnedDevices) { if (!device.getDeviceIdentifier().startsWith(DEVICE_ID_PREFIX)) { throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!"); } } deviceAccessAuthorizationService = Mockito.mock(DeviceAccessAuthorizationServiceImpl.class, Mockito.CALLS_REAL_METHODS); defaultUserClaims = buildDefaultUserClaims(FIRST_NAME, LAST_NAME, EMAIL); initializeTestEnvironment(); PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true); }