Source:
public void testVerifyManifestPermission_missingPermission_MANAGE_ACCOUNTS() throws NoSuchAlgorithmException, NoSuchPaddingException, IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, NameNotFoundException, NoSuchFieldException { FileMockContext mockContext = new FileMockContext(getContext()); mockContext.setPermission("android.permission.INTERNET",PackageManager.PERMISSION_GRANTED); mockContext.setPermission("android.permission.GET_ACCOUNTS",PackageManager.PERMISSION_GRANTED); mockContext.setPermission("android.permission.USE_CREDENTIALS",PackageManager.PERMISSION_GRANTED); Object brokerProxy = ReflectionUtils.getInstance("com.microsoft.aad.adal.BrokerProxy"); String authenticatorType = AuthenticationConstants.Broker.BROKER_ACCOUNT_TYPE; String brokerPackage = AuthenticationConstants.Broker.PACKAGE_NAME; String contextPackage = "com.test"; Signature signature = new Signature(testSignature); AuthenticationSettings.INSTANCE.setBrokerSignature(testTag); Account[] accts = getAccountList("currentUserName", authenticatorType); prepareProxyForTest(brokerProxy, authenticatorType, brokerPackage, contextPackage, signature, true, accts); ReflectionUtils.setFieldValue(brokerProxy, "mContext", mockContext); Method m = ReflectionUtils.getTestMethod(brokerProxy, "verifyManifestPermissions"); try { m.invoke(brokerProxy); Assert.fail(); } catch(InvocationTargetException e) { assertTrue(e.getCause() instanceof DeveloperAuthenticationException); assertTrue(((DeveloperAuthenticationException)e.getCause()).getMessage().contains("[MANAGE_ACCOUNTS]")); assertEquals(ADALError.DEVELOPER_BROKER_PERMISSIONS_MISSING,((DeveloperAuthenticationException)e.getCause()).getCode()); } }

Target:
public void testVerifyManifestPermission_missingPermission_MANAGE_ACCOUNTS() throws NoSuchAlgorithmException, IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, NameNotFoundException, NoSuchFieldException { FileMockContext mockContext = new FileMockContext(getContext()); mockContext.setPermission("android.permission.INTERNET",PackageManager.PERMISSION_GRANTED); mockContext.setPermission("android.permission.GET_ACCOUNTS",PackageManager.PERMISSION_GRANTED); mockContext.setPermission("android.permission.USE_CREDENTIALS",PackageManager.PERMISSION_GRANTED); Object brokerProxy = ReflectionUtils.getInstance("com.microsoft.aad.adal.BrokerProxy"); String authenticatorType = AuthenticationConstants.Broker.BROKER_ACCOUNT_TYPE; String brokerPackage = AuthenticationConstants.Broker.COMPANY_PORTAL_APP_PACKAGE_NAME; String contextPackage = "com.test"; Signature signature = new Signature(testSignature); AuthenticationSettings.INSTANCE.setBrokerSignature(testTag); Account[] accts = getAccountList("currentUserName", authenticatorType); prepareProxyForTest(brokerProxy, authenticatorType, brokerPackage, contextPackage, signature, true, accts); ReflectionUtils.setFieldValue(brokerProxy, "mContext", mockContext); Method m = ReflectionUtils.getTestMethod(brokerProxy, "verifyManifestPermissions"); try { m.invoke(brokerProxy); Assert.fail(); } catch(InvocationTargetException e) { assertTrue(e.getCause() instanceof UsageAuthenticationException); assertTrue(((UsageAuthenticationException)e.getCause()).getMessage().contains("[MANAGE_ACCOUNTS]")); assertEquals(ADALError.DEVELOPER_BROKER_PERMISSIONS_MISSING, ((UsageAuthenticationException)e.getCause()).getCode()); } }