StackdriverLogging implements BackgroundFunction<PubSubMessage> { @Override public void accept(PubSubMessage message, Context context) { String name = "World"; if (!message.getData().isEmpty()) { name = new String(Base64.getDecoder().decode( message.getData().getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); } String res = String.format("Hello, %s", name); logger.info(res); }  @Override void accept(PubSubMessage message, Context context);  }
@Test public void stackdriverLogging() throws IOException { String messageJson = gson.toJson(Map.of( "data", "ZGF0YQ==", "messageId", "id" )); PubSubMessage pubsubMessage = gson.fromJson(messageJson, PubSubMessage.class); new StackdriverLogging().accept(pubsubMessage, null); String logMessage = LOG_HANDLER.getStoredLogRecords().get(0).getMessage(); assertThat("Hello, data").isEqualTo(logMessage); }