// Path: java-runtime-builder-app/src/test/java/com/google/cloud/runtimes/builder/TestUtils.java
// public static class TestWorkspaceBuilder {
// 
//   private final Path workspaceDir;
// 
//   public TestWorkspaceBuilder() throws IOException {
//     this.workspaceDir = Files.createTempDirectory(null);
//   }
// 
//   public FileBuilder file(String path) {
//     return new FileBuilder(this, workspaceDir.resolve(path));
//   }
// 
//   public Path build() {
//     return workspaceDir;
//   }
// 
//   public class FileBuilder {
//     private final Path path;
//     private final TestWorkspaceBuilder workspaceBuilder;
//     private String contents = "";
//     private boolean isExecutable = false;
// 
//     private FileBuilder(TestWorkspaceBuilder workspaceBuilder, Path path) {
//       this.workspaceBuilder = workspaceBuilder;
//       this.path = path;
//     }
// 
//     public FileBuilder withContents(String contents) {
//       this.contents = contents;
//       return this;
//     }
// 
//     public FileBuilder setIsExecutable(boolean isExecutable) {
//       this.isExecutable = isExecutable;
//       return this;
//     }
// 
//     public TestWorkspaceBuilder build() throws IOException {
//       // mkdir -p
//       Files.createDirectories(path.getParent());
// 
//       try (Writer out = Files.newBufferedWriter(path, Charset.defaultCharset())) {
//         out.write(contents);
//       }
// 
//       Set<PosixFilePermission> permissions = Sets.newHashSet(
//           PosixFilePermission.OWNER_READ,
//           PosixFilePermission.OWNER_WRITE);
//       if (isExecutable) {
//         permissions.add(PosixFilePermission.OWNER_EXECUTE);
//       }
// 
//       Files.setPosixFilePermissions(path, permissions);
//       return workspaceBuilder;
//     }
//   }
// }


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import com.google.cloud.runtimes.builder.TestUtils.TestWorkspaceBuilder;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.Before;
import org.junit.Test;
  }

  @Test
  public void testWriteDockerFilesWithEmptyBuffers() throws IOException {
    initBuildContext().writeDockerResources();
    assertEquals("", readFile(getDockerfile()));
    assertFalse(Files.exists(workspace.resolve(".dockerfile")));
  }

  @Test
  public void testWriteDockerFilesWithExistingDockerignore() throws IOException {
    String dockerIgnoreContents = "foo/**\nbar";
    workspace = new TestWorkspaceBuilder()
        .file(".dockerignore").withContents(dockerIgnoreContents).build()
        .build();

    BuildContext context = initBuildContext();
    String dockerIgnoreAppend = "more_paths";
    context.getDockerignore().appendLine(dockerIgnoreAppend);

    context.writeDockerResources();
    assertEquals("", readFile(getDockerfile()));
    assertEquals(dockerIgnoreContents + "\n" + DOCKER_IGNORE_PREAMBLE + dockerIgnoreAppend + "\n",
        readFile(getDockerIgnore()));
  }

  @Test
  public void testWriteDockerFilesWithExistingDockerignoreTerminalNewline() throws IOException {
    String commonIgnoreLine = "foo/**";
    String dockerIgnoreContents = commonIgnoreLine + "\nbar\n";
// Path: java-runtime-builder-app/src/test/java/com/google/cloud/runtimes/builder/TestUtils.java
// public static class TestWorkspaceBuilder {
// 
//   private final Path workspaceDir;
// 
//   public TestWorkspaceBuilder() throws IOException {
//     this.workspaceDir = Files.createTempDirectory(null);
//   }
// 
//   public FileBuilder file(String path) {
//     return new FileBuilder(this, workspaceDir.resolve(path));
//   }
// 
//   public Path build() {
//     return workspaceDir;
//   }
// 
//   public class FileBuilder {
//     private final Path path;
//     private final TestWorkspaceBuilder workspaceBuilder;
//     private String contents = "";
//     private boolean isExecutable = false;
// 
//     private FileBuilder(TestWorkspaceBuilder workspaceBuilder, Path path) {
//       this.workspaceBuilder = workspaceBuilder;
//       this.path = path;
//     }
// 
//     public FileBuilder withContents(String contents) {
//       this.contents = contents;
//       return this;
//     }
// 
//     public FileBuilder setIsExecutable(boolean isExecutable) {
//       this.isExecutable = isExecutable;
//       return this;
//     }
// 
//     public TestWorkspaceBuilder build() throws IOException {
//       // mkdir -p
//       Files.createDirectories(path.getParent());
// 
//       try (Writer out = Files.newBufferedWriter(path, Charset.defaultCharset())) {
//         out.write(contents);
//       }
// 
//       Set<PosixFilePermission> permissions = Sets.newHashSet(
//           PosixFilePermission.OWNER_READ,
//           PosixFilePermission.OWNER_WRITE);
//       if (isExecutable) {
//         permissions.add(PosixFilePermission.OWNER_EXECUTE);
//       }
// 
//       Files.setPosixFilePermissions(path, permissions);
//       return workspaceBuilder;
//     }
//   }
// }


// Path: java-runtime-builder-app/src/test/java/com/google/cloud/runtimes/builder/config/domain/BuildContextTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import com.google.cloud.runtimes.builder.TestUtils.TestWorkspaceBuilder;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.Before;
import org.junit.Test;

  }

  @Test
  public void testWriteDockerFilesWithEmptyBuffers() throws IOException {
    initBuildContext().writeDockerResources();
    assertEquals("", readFile(getDockerfile()));
    assertFalse(Files.exists(workspace.resolve(".dockerfile")));
  }

  @Test
  public void testWriteDockerFilesWithExistingDockerignore() throws IOException {
    String dockerIgnoreContents = "foo/**\nbar";
    workspace = new TestWorkspaceBuilder()
        .file(".dockerignore").withContents(dockerIgnoreContents).build()
        .build();

    BuildContext context = initBuildContext();
    String dockerIgnoreAppend = "more_paths";
    context.getDockerignore().appendLine(dockerIgnoreAppend);

    context.writeDockerResources();
    assertEquals("", readFile(getDockerfile()));
    assertEquals(dockerIgnoreContents + "\n" + DOCKER_IGNORE_PREAMBLE + dockerIgnoreAppend + "\n",
        readFile(getDockerIgnore()));
  }

  @Test
  public void testWriteDockerFilesWithExistingDockerignoreTerminalNewline() throws IOException {
    String commonIgnoreLine = "foo/**";
    String dockerIgnoreContents = commonIgnoreLine + "\nbar\n";
    workspace = new TestWorkspaceBuilder()