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); } } }
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 QueryAndOutput( CancellationToken cancelToken, AsyncDataState firstState, AsyncDataQuery<? super DataType, ? extends SourceDataType> query, AsyncDataListener<? super SourceDataType> outputListener) { ExceptionHelper.checkNotNullArgument(cancelToken, "cancelToken"); ExceptionHelper.checkNotNullArgument(query, "query"); ExceptionHelper.checkNotNullArgument(outputListener, "outputListener"); this.cancelToken = cancelToken; this.query = query; this.outputListener = outputListener; this.mainLock = new ReentrantLock(); this.eventScheduler = TaskExecutors.inOrderSyncExecutor(); this.dataForwarderTask = new DataForwardTask(); this.currentSession = null; this.currentController = new InitLaterDataController(firstState); this.initializedController = false; this.unsentData = null; this.sessionReport = AsyncReport.SUCCESS; this.endReport = null; this.finished = false; }