public void testUnreadableFile(ImageResultVerifier... verifiers) throws Exception { Path testPath = Paths.get( "this-should-not-exist", "really", "please", "dont", "create", "this", "directory", "tree"); final ContextAwareTaskExecutor taskExecutor = TaskExecutors.contextAware(SyncTaskExecutor.getSimpleExecutor()); AsyncDataLink<ImageResult> link = create(testPath, taskExecutor); ImageCollectorListener listener = new ImageCollectorListener(taskExecutor); AsyncDataController controller = link.getData(Cancellation.UNCANCELABLE_TOKEN, listener); assertNotNull(controller.getDataState()); controller.controlData(null); AsyncReport report = listener.getReport(); ImageResult lastResult = listener.getLastResult(); long imageCount = listener.getImageCount(); listener.verifyNoTrivialErrors(); assertEquals("Should not have received an image.", 0L, imageCount); ImageResultVerifier verifier = combineVerifiers(new FailedVerifier(Throwable.class), combineVerifiers(verifiers)); verifier.verifyImageResult(imageCount, lastResult, report); }
public void testInvalidFormat(ImageResultVerifier... verifiers) throws IOException { Path tempFile = null; try { tempFile = Files.createTempFile("jtrim", ".test"); final ContextAwareTaskExecutor taskExecutor = TaskExecutors.contextAware(SyncTaskExecutor.getSimpleExecutor()); AsyncDataLink<ImageResult> link = create(tempFile, taskExecutor); ImageCollectorListener listener = new ImageCollectorListener(taskExecutor); AsyncDataController controller = link.getData(Cancellation.UNCANCELABLE_TOKEN, listener); assertNotNull(controller.getDataState()); controller.controlData(null); AsyncReport report = listener.getReport(); ImageResult lastResult = listener.getLastResult(); long imageCount = listener.getImageCount(); listener.verifyNoTrivialErrors(); assertEquals("Should not have received an image.", 0L, imageCount); ImageResultVerifier verifier = combineVerifiers(new FailedVerifier(Throwable.class), combineVerifiers(verifiers)); verifier.verifyImageResult(imageCount, lastResult, report); } finally { if (tempFile != null) { Files.deleteIfExists(tempFile); } } }