PDDocumentAccessPermission { public void ensurePermission(PdfAccessPermission required) throws TaskPermissionsException { if (!Boolean.getBoolean(Sejda.UNETHICAL_READ_PROPERTY_NAME) && !ForwardingPdfAccessPermission.valueFromPdfAccessPermission(required).isAllowed(permissions)) { throw new TaskPermissionsException(String.format("Permission %s is not granted.", required)); } } PDDocumentAccessPermission(PDDocument document); void ensureOwnerPermissions(); void ensurePermission(PdfAccessPermission required);  }
@Test(expected = TaskPermissionsException.class) public void testNotPrint() throws TaskPermissionsException { when(permission.canPrint()).thenReturn(Boolean.FALSE); victim.ensurePermission(PdfAccessPermission.PRINT); }
@Test public void testPrint() throws TaskPermissionsException { when(permission.canPrint()).thenReturn(Boolean.TRUE); victim.ensurePermission(PdfAccessPermission.PRINT); }
@Test public void testPrintUnethical() throws TaskPermissionsException { System.setProperty(Sejda.UNETHICAL_READ_PROPERTY_NAME, "true"); when(permission.canPrint()).thenReturn(Boolean.FALSE); victim.ensurePermission(PdfAccessPermission.PRINT); System.setProperty(Sejda.UNETHICAL_READ_PROPERTY_NAME, "false"); }
@Test(expected = TaskPermissionsException.class) public void testNotDegradedPrint() throws TaskPermissionsException { when(permission.canPrintDegraded()).thenReturn(Boolean.FALSE); victim.ensurePermission(PdfAccessPermission.DEGRADATED_PRINT); }
@Test public void testDegradedPrint() throws TaskPermissionsException { when(permission.canPrintDegraded()).thenReturn(Boolean.TRUE); victim.ensurePermission(PdfAccessPermission.DEGRADATED_PRINT); }
@Test(expected = TaskPermissionsException.class) public void testNotAssemble() throws TaskPermissionsException { when(permission.canAssembleDocument()).thenReturn(Boolean.FALSE); victim.ensurePermission(PdfAccessPermission.ASSEMBLE); }
@Test public void testAssemble() throws TaskPermissionsException { when(permission.canAssembleDocument()).thenReturn(Boolean.TRUE); victim.ensurePermission(PdfAccessPermission.ASSEMBLE); }
@Test(expected = TaskPermissionsException.class) public void testNotAannotation() throws TaskPermissionsException { when(permission.canModifyAnnotations()).thenReturn(Boolean.FALSE); victim.ensurePermission(PdfAccessPermission.ANNOTATION); }
@Test public void testAnnotation() throws TaskPermissionsException { when(permission.canModifyAnnotations()).thenReturn(Boolean.TRUE); victim.ensurePermission(PdfAccessPermission.ANNOTATION); }
@Test(expected = TaskPermissionsException.class) public void testNotCopy() throws TaskPermissionsException { when(permission.canExtractContent()).thenReturn(Boolean.FALSE); victim.ensurePermission(PdfAccessPermission.COPY_AND_EXTRACT); }
@Test public void testCopy() throws TaskPermissionsException { when(permission.canExtractContent()).thenReturn(Boolean.TRUE); victim.ensurePermission(PdfAccessPermission.COPY_AND_EXTRACT); }
@Test(expected = TaskPermissionsException.class) public void testNotExtract() throws TaskPermissionsException { when(permission.canExtractForAccessibility()).thenReturn(Boolean.FALSE); victim.ensurePermission(PdfAccessPermission.EXTRACTION_FOR_DISABLES); }
@Test public void testExtract() throws TaskPermissionsException { when(permission.canExtractForAccessibility()).thenReturn(Boolean.TRUE); victim.ensurePermission(PdfAccessPermission.EXTRACTION_FOR_DISABLES); }
@Test(expected = TaskPermissionsException.class) public void testNotFillForm() throws TaskPermissionsException { when(permission.canFillInForm()).thenReturn(Boolean.FALSE); victim.ensurePermission(PdfAccessPermission.FILL_FORMS); }
@Test public void testFillForm() throws TaskPermissionsException { when(permission.canFillInForm()).thenReturn(Boolean.TRUE); victim.ensurePermission(PdfAccessPermission.FILL_FORMS); }
@Test(expected = TaskPermissionsException.class) public void testNotModify() throws TaskPermissionsException { when(permission.canModify()).thenReturn(Boolean.FALSE); victim.ensurePermission(PdfAccessPermission.MODIFY); }
@Test public void testModify() throws TaskPermissionsException { when(permission.canModify()).thenReturn(Boolean.TRUE); victim.ensurePermission(PdfAccessPermission.MODIFY); }
@Test(expected = IllegalArgumentException.class) public void testNullPermission() throws TaskPermissionsException { victim.ensurePermission(null); }