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;
        translator = DisplayDataTranslation::translate;
      }
      builder.add(
          RunnerApi.DisplayData.newBuilder()
              .setUrn(urn)
              .setPayload(translator.apply(item))
              .build());
    }
    return builder.build();
  }
@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"));
                    builder.add(DisplayData.item("foo3", true).withLabel("label"));
                    builder.add(DisplayData.item("foo4", 123.4).withLabel("label"));
                    builder.add(DisplayData.item("foo5", 4.321f).withLabel("label"));
                    builder.add(DisplayData.item("foo6", 321).withLabel("label"));
                    builder.add(DisplayData.item("foo7", 123L).withLabel("label"));
                  }
                })),
        containsInAnyOrder(
            RunnerApi.DisplayData.newBuilder()
                .setUrn(DisplayDataTranslation.LABELLED)
                .setPayload(
                    RunnerApi.LabelledPayload.newBuilder()
                        .setLabel("foo")
                        .setStringValue("value")
                        .setKey("foo")
                        .setNamespace(
                            "org.apache.beam.sdk.util.construction.DisplayDataTranslationTest$1")
                        .build()
                        .toByteString())
                .build(),
            RunnerApi.DisplayData.newBuilder()
                .setUrn(DisplayDataTranslation.LABELLED)
                .setPayload(
                    RunnerApi.LabelledPayload.newBuilder()
                        .setLabel("label")
                        .setStringValue("value2")
                        .setKey("foo2")
                        .setNamespace(
                            "org.apache.beam.sdk.util.construction.DisplayDataTranslationTest$1")
                        .build()
                        .toByteString())
                .build(),
            RunnerApi.DisplayData.newBuilder()
                .setUrn(DisplayDataTranslation.LABELLED)
                .setPayload(
                    RunnerApi.LabelledPayload.newBuilder()
                        .setLabel("label")
                        .setBoolValue(true)
                        .setKey("foo3")
                        .setNamespace(
                            "org.apache.beam.sdk.util.construction.DisplayDataTranslationTest$1")
                        .build()
                        .toByteString())
                .build(),
            RunnerApi.DisplayData.newBuilder()
                .setUrn(DisplayDataTranslation.LABELLED)
                .setPayload(
                    RunnerApi.LabelledPayload.newBuilder()
                        .setLabel("label")
                        .setDoubleValue(123.4)
                        .setKey("foo4")
                        .setNamespace(
                            "org.apache.beam.sdk.util.construction.DisplayDataTranslationTest$1")
                        .build()
                        .toByteString())
                .build(),
            RunnerApi.DisplayData.newBuilder()
                .setUrn(DisplayDataTranslation.LABELLED)
                .setPayload(
                    RunnerApi.LabelledPayload.newBuilder()
                        .setLabel("label")
                        .setDoubleValue(4.321000099182129)
                        .setKey("foo5")
                        .setNamespace(
                            "org.apache.beam.sdk.util.construction.DisplayDataTranslationTest$1")
                        .build()
                        .toByteString())
                .build(),
            RunnerApi.DisplayData.newBuilder()
                .setUrn(DisplayDataTranslation.LABELLED)
                .setPayload(
                    RunnerApi.LabelledPayload.newBuilder()
                        .setLabel("label")
                        .setIntValue(321)
                        .setKey("foo6")
                        .setNamespace(
                            "org.apache.beam.sdk.util.construction.DisplayDataTranslationTest$1")
                        .build()
                        .toByteString())
                .build(),
            RunnerApi.DisplayData.newBuilder()
                .setUrn(DisplayDataTranslation.LABELLED)
                .setPayload(
                    RunnerApi.LabelledPayload.newBuilder()
                        .setLabel("label")
                        .setIntValue(123)
                        .setKey("foo7")
                        .setNamespace(
                            "org.apache.beam.sdk.util.construction.DisplayDataTranslationTest$1")
                        .build()
                        .toByteString())
                .build()));
  }