@VisibleForTesting
  protected Pipeline writeArtifacts(Pipeline pipeline, String jobName) throws IOException {
    Pipeline.Builder result = pipeline.toBuilder();
    for (Map.Entry<String, RunnerApi.Environment> env :
        pipeline.getComponents().getEnvironmentsMap().entrySet()) {
      result
          .getComponentsBuilder()
          .putEnvironments(env.getKey(), writeArtifacts(env.getValue(), jobName));
    }
    return result.build();
  }
@Test
  public void testWriteArtifacts_copiesArtifactsIntoJar() throws IOException {
    RunnerApi.ArtifactInformation artifact =
        RunnerApi.ArtifactInformation.newBuilder()
            .setTypeUrn(ArtifactRetrievalService.EMBEDDED_ARTIFACT_URN)
            .setTypePayload(
                RunnerApi.EmbeddedFilePayload.newBuilder()
                    .setData(ByteString.copyFromUtf8("someData"))
                    .build()
                    .toByteString())
            .setRoleUrn("someRole")
            .build();
    RunnerApi.Pipeline pipeline =
        RunnerApi.Pipeline.newBuilder()
            .setComponents(
                RunnerApi.Components.newBuilder()
                    .putEnvironments(
                        "env", RunnerApi.Environment.newBuilder().addDependencies(artifact).build())
                    .build())
            .build();
    RunnerApi.Pipeline newPipeline = jarCreator.writeArtifacts(pipeline, "jobName");
    verify(outputStream, times(1)).putNextEntry(any());
    RunnerApi.ArtifactInformation newArtifact =
        newPipeline.getComponents().getEnvironmentsMap().get("env").getDependencies(0);
    assertEquals(artifact.getRoleUrn(), newArtifact.getRoleUrn());
    assertNotEquals(artifact.getTypePayload(), newArtifact.getTypePayload());
  }