DisplayDataTranslation { public static List<RunnerApi.DisplayData> toProto(DisplayData displayData) { ImmutableList.Builder<RunnerApi.DisplayData> builder = ImmutableList.builder(); for (DisplayData.Item item : displayData.items()) { Function<DisplayData.Item, ByteString> translator = WELL_KNOWN_URN_TRANSLATORS.get(item.getKey()); String urn; if (translator != null) { urn = item.getKey(); } else { urn = LABELLED_STRING; translator = DisplayDataTranslation::translateStringUtf8; } builder.add( RunnerApi.DisplayData.newBuilder() .setUrn(urn) .setPayload(translator.apply(item)) .build()); } return builder.build(); }  static List<RunnerApi.DisplayData> toProto(DisplayData displayData); static final String LABELLED_STRING; }
@Test public void testTranslation() { assertThat( DisplayDataTranslation.toProto( DisplayData.from( new HasDisplayData() { @Override public void populateDisplayData(DisplayData.Builder builder) { builder.add(DisplayData.item("foo", "value")); builder.add(DisplayData.item("foo2", "value2").withLabel("label")); } })), containsInAnyOrder( RunnerApi.DisplayData.newBuilder() .setUrn(DisplayDataTranslation.LABELLED_STRING) .setPayload( RunnerApi.LabelledStringPayload.newBuilder() .setLabel("foo") .setValue("value") .build() .toByteString()) .build(), RunnerApi.DisplayData.newBuilder() .setUrn(DisplayDataTranslation.LABELLED_STRING) .setPayload( RunnerApi.LabelledStringPayload.newBuilder() .setLabel("label") .setValue("value2") .build() .toByteString()) .build())); }