### Question:
BulkRotateTask extends BaseTask<BulkRotateParameters> { @Override public void execute(BulkRotateParameters parameters) throws TaskException { int currentStep = 0; for (PdfRotationInput input : parameters.getInputSet()) { executionContext().assertTaskNotCancelled(); currentStep++; LOG.debug("Opening {}", input.source); try { documentHandler = input.source.open(documentLoader); documentHandler.getPermissions().ensurePermission(PdfAccessPermission.ASSEMBLE); documentHandler.setCreatorOnPDDocument(); File tmpFile = createTemporaryBuffer(parameters.getOutput()); LOG.debug("Created output on temporary buffer {}", tmpFile); PdfRotator rotator = new PdfRotator(documentHandler.getUnderlyingPDDocument()); for (Integer page : input.getPages(documentHandler.getNumberOfPages())) { executionContext().assertTaskNotCancelled(); rotator.rotate(page, input.rotation); } documentHandler.setVersionOnPDDocument(parameters.getVersion()); documentHandler.setCompress(parameters.isCompress()); documentHandler.savePDDocument(tmpFile, parameters.getOutput().getEncryptionAtRestPolicy()); String outName = nameGenerator(parameters.getOutputPrefix()) .generate(nameRequest().originalName(input.source.getName()).fileNumber(currentStep)); outputWriter.addOutput(file(tmpFile).name(outName)); } finally { closeQuietly(documentHandler); } notifyEvent(executionContext().notifiableTaskMetadata()).stepsCompleted(currentStep).outOf(totalSteps); } parameters.getOutput().accept(outputWriter); LOG.debug("Input documents rotated and written to {}", parameters.getOutput()); }  @Override void before(BulkRotateParameters parameters, TaskExecutionContext executionContext); @Override void execute(BulkRotateParameters parameters); @Override void after();  }### Answer:
@Test public void testExecute() throws IOException { setUpDefaultParameters(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertPages(4) .forEachPdfOutput(d -> d.getPages().forEach(p -> assertEquals(180, p.getRotation()))); }
@Test public void testRotateSpecificPages() throws IOException { setUpRotateSpecificPages(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertPages(4).forEachPdfOutput(d -> assertEquals(90, d.getPage(2).getRotation())); }
@Test public void testExecuteEncrypted() throws IOException { setUpParametersEncrypted(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertPages(4) .forEachPdfOutput(d -> d.getPages().forEach(p -> assertEquals(180, p.getRotation()))); }
@Test public void testVersionPrefixAndCreatorAreApplied() throws IOException { setUpParametersWithVersionPrefixAndCompressionSpecified(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertCreator().assertPages(4).assertVersion(PdfVersion.VERSION_1_6); }
@Test public void testMultipleInputOneDoesntContainRange() throws IOException { setUpRotateMultipleInput(); testContext.directoryOutputTo(parameters); execute(parameters); testContext.assertTaskCompleted(); testContext.assertOutputSize(2).forEachPdfOutput(d -> { assertEquals(90, d.getPage(1).getRotation()); assertEquals(90, d.getPage(2).getRotation()); assertEquals(90, d.getPage(3).getRotation()); }); }