HelloPubSub implements BackgroundFunction<PubSubMessage> { @Override public void accept(PubSubMessage message, Context context) { String name = "world"; if (message != null && message.getData() != null) { name = new String( Base64.getDecoder().decode(message.getData().getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); } logger.info(String.format("Hello %s!", name)); return; }  @Override void accept(PubSubMessage message, Context context);  }
@Test public void helloPubSub_shouldPrintName() { PubSubMessage pubSubMessage = new PubSubMessage(); pubSubMessage.setData(Base64.getEncoder().encodeToString( "John".getBytes(StandardCharsets.UTF_8))); sampleUnderTest.accept(pubSubMessage, null); String logMessage = LOG_HANDLER.getStoredLogRecords().get(0).getMessage(); assertThat("Hello John!").isEqualTo(logMessage); }
@Test public void helloPubSub_shouldPrintHelloWorld() { PubSubMessage pubSubMessage = new PubSubMessage(); sampleUnderTest.accept(pubSubMessage, null); String logMessage = LOG_HANDLER.getStoredLogRecords().get(0).getMessage(); assertThat("Hello world!").isEqualTo(logMessage); }