OcrProcessImage implements BackgroundFunction<GcsEvent> { @Override public void accept(GcsEvent gcsEvent, Context context) { String bucket = gcsEvent.getBucket(); if (bucket == null) { throw new IllegalArgumentException("Missing bucket parameter"); } String filename = gcsEvent.getName(); if (filename == null) { throw new IllegalArgumentException("Missing name parameter"); } detectText(bucket, filename); } OcrProcessImage(); @Override void accept(GcsEvent gcsEvent, Context context);  }
@Test(expected = IllegalArgumentException.class) public void functionsOcrProcess_shouldValidateParams() throws IOException { sampleUnderTest.accept(new GcsEvent(), null); }
@Test public void functionsOcrProcess_shouldDetectText() throws IOException { GcsEvent gcsEvent = new GcsEvent(); gcsEvent.setBucket(FUNCTIONS_BUCKET); gcsEvent.setName("wakeupcat.jpg"); sampleUnderTest.accept(gcsEvent, null); List<LogRecord> logs = LOG_HANDLER.getStoredLogRecords(); Truth.assertThat(logs.get(1).getMessage()).contains( "Extracted text from image: Wake up human!"); Truth.assertThat(logs.get(2).getMessage()).contains( "Detected language en for file wakeupcat.jpg"); }