Source:
<code>public void testVerifyManifestPermission_missingPermission_GET_ACCOUNT() throws NoSuchAlgorithmException, NoSuchPaddingException, IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, NameNotFoundException, NoSuchFieldException { FileMockContext mockContext = new FileMockContext(getContext()); <START> mockContext.setPermission("android.permission.INTERNET",PackageManager.PERMISSION_GRANTED); <END> mockContext.setPermission("android.permission.MANAGE_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("It is expected to return an exception here."); } catch(InvocationTargetException e) { assertTrue(e.getCause() instanceof UsageAuthenticationException); assertTrue(((UsageAuthenticationException)e.getCause()).getMessage().toString().contains("[GET_ACCOUNTS]")); assertEquals(ADALError.DEVELOPER_BROKER_PERMISSIONS_MISSING, ((UsageAuthenticationException)e.getCause()).getCode()); } }</code><technical_language>code line 316-325 is repeated in tests, try refactor a bit</technical_language>

Target:
public void testVerifyManifestPermission_missingPermission_GET_ACCOUNT() 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.MANAGE_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("It is expected to return an exception here."); } catch(InvocationTargetException e) { assertTrue(e.getCause() instanceof UsageAuthenticationException); assertTrue(((UsageAuthenticationException)e.getCause()).getMessage().toString().contains("[GET_ACCOUNTS]")); assertEquals(ADALError.DEVELOPER_BROKER_PERMISSIONS_MISSING, ((UsageAuthenticationException)e.getCause()).getCode()); } }