AccessChecker implements Serializable { public void check(Metadata metadata) throws AccessPermissionException { if (!needToCheck) { return; } if ("false".equals(metadata.get(AccessPermissions.EXTRACT_CONTENT))) { if (allowAccessibility) { if ("true".equals(metadata.get(AccessPermissions.EXTRACT_FOR_ACCESSIBILITY))) { return; } throw new AccessPermissionException("Content extraction for accessibility is not allowed."); } throw new AccessPermissionException("Content extraction is not allowed."); } } AccessChecker();  AccessChecker(boolean allowExtractionForAccessibility); void check(Metadata metadata); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testLegacy() throws AccessPermissionException { Metadata m = getMetadata(false, false); AccessChecker checker = new AccessChecker(); checker.check(m); assertTrue("no exception", true); m = getMetadata(false, true); assertTrue("no exception", true); checker.check(m); m = getMetadata(true, true); assertTrue("no exception", true); checker.check(m); }
@Test public void testNoExtraction() { Metadata m = null; AccessChecker checker = new AccessChecker(false); boolean ex = false; try { m = getMetadata(false, false); checker.check(m); } catch (AccessPermissionException e) { ex = true; } assertTrue("correct exception with no extraction, no extract for accessibility", ex); ex = false; try { m = getMetadata(false, true); checker.check(m); } catch (AccessPermissionException e) { ex = true; } assertTrue("correct exception with no extraction, no extract for accessibility", ex); }
@Test public void testExtractOnlyForAccessibility() throws AccessPermissionException { Metadata m = getMetadata(false, true); AccessChecker checker = new AccessChecker(true); checker.check(m); assertTrue("no exception", true); boolean ex = false; try { m = getMetadata(false, false); checker.check(m); } catch (AccessPermissionException e) { ex = true; } assertTrue("correct exception", ex); }
@Test public void testCrazyExtractNotForAccessibility() throws AccessPermissionException { Metadata m = getMetadata(true, false); AccessChecker checker = new AccessChecker(true); checker.check(m); assertTrue("no exception", true); checker = new AccessChecker(false); checker.check(m); assertTrue("no exception", true); }