@Test(description = "Testing get devices when user is unauthorized.")
public void testGetDevicesWhenUserIsUnauthorized() throws Exception {

    PowerMockito.spy(MultitenantUtils.class);
    PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
            .toReturn(this.deviceManagementProviderService);
    PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
            .toReturn(this.deviceAccessAuthorizationService);
    PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
            .toReturn(Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS));
    PowerMockito.doReturn(TENANT_AWARE_USERNAME)
            .when(MultitenantUtils.class, "getTenantAwareUsername", DEFAULT_USERNAME);
    PowerMockito.doReturn("newuser@carbon.super").when(MultitenantUtils.class, "getTenantAwareUsername", "newuser");
    Mockito.when(this.deviceAccessAuthorizationService.isDeviceAdminUser()).thenReturn(false);
    Response response = this.deviceManagementService
            .getDevices(null, TEST_DEVICE_TYPE, "newuser", null, DEFAULT_ROLE, DEFAULT_OWNERSHIP, DEFAULT_STATUS, 1,
                    null, null, 10, 5);
    Assert.assertEquals(response.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode());
    Mockito.reset(this.deviceAccessAuthorizationService);
}