Repository: GoogleContainerTools/jib
File: jib-cli/src/test/java/com/google/cloud/tools/jib/cli/ContainerBuildersTest.java (Java)

Code before:
import com.google.cloud.tools.jib.configuration.ImageConfiguration;
import com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger;
import com.google.common.collect.ImmutableSet;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.Optional;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

/** Tests for {@link ContainerBuilders}. */
@RunWith(MockitoJUnitRunner.class)
public class ContainerBuildersTest {

  @Mock private CommonCliOptions mockCommonCliOptions;

  @Mock private ConsoleLogger mockLogger;

  @Test
  public void testCreate_dockerBaseImage()
      throws IOException, InvalidImageReferenceException, CacheDirectoryCreationException {
    JibContainerBuilder containerBuilder =
        ContainerBuilders.create(
            "docker://docker-image-ref", Collections.EMPTY_SET, mockCommonCliOptions, mockLogger);
    BuildContext buildContext =
        JibContainerBuilderTestHelper.toBuildContext(
            containerBuilder, Containerizer.to(RegistryImage.named("ignored")));
    ImageConfiguration imageConfiguration = buildContext.getBaseImageConfiguration();

    assertThat(imageConfiguration.getImage().toString()).isEqualTo("docker-image-ref");
    assertThat(imageConfiguration.getDockerClient().isPresent()).isTrue();
    assertThat(imageConfiguration.getTarPath().isPresent()).isFalse();
  }

  @Test
  public void testCreate_registry()
      throws IOException, InvalidImageReferenceException, CacheDirectoryCreationException {
    JibContainerBuilder containerBuilder =
        ContainerBuilders.create(
            "registry://registry-image-ref",
            Collections.EMPTY_SET,
            mockCommonCliOptions,
            mockLogger);
    BuildContext buildContext =
        JibContainerBuilderTestHelper.toBuildContext(
            containerBuilder, Containerizer.to(RegistryImage.named("ignored")));
    ImageConfiguration imageConfiguration = buildContext.getBaseImageConfiguration();

    assertThat(imageConfiguration.getImage().toString()).isEqualTo("registry-image-ref");

Review comment (bug):
Sorry, missed this. Let's use `Collections.emptyList()` and `.emptySet()`. https://stackoverflow.com/q/14870819/1701388

Code after:
import com.google.cloud.tools.jib.configuration.ImageConfiguration;
import com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger;
import com.google.common.collect.ImmutableSet;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.Optional;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

/** Tests for {@link ContainerBuilders}. */
@RunWith(MockitoJUnitRunner.class)
public class ContainerBuildersTest {

  @Mock private CommonCliOptions mockCommonCliOptions;

  @Mock private ConsoleLogger mockLogger;

  @Test
  public void testCreate_dockerBaseImage()
      throws IOException, InvalidImageReferenceException, CacheDirectoryCreationException {
    JibContainerBuilder containerBuilder =
        ContainerBuilders.create(
            "docker://docker-image-ref", Collections.emptySet(), mockCommonCliOptions, mockLogger);
    BuildContext buildContext =
        JibContainerBuilderTestHelper.toBuildContext(
            containerBuilder, Containerizer.to(RegistryImage.named("ignored")));
    ImageConfiguration imageConfiguration = buildContext.getBaseImageConfiguration();

    assertThat(imageConfiguration.getImage().toString()).isEqualTo("docker-image-ref");
    assertThat(imageConfiguration.getDockerClient().isPresent()).isTrue();
    assertThat(imageConfiguration.getTarPath().isPresent()).isFalse();
  }

  @Test
  public void testCreate_registry()
      throws IOException, InvalidImageReferenceException, CacheDirectoryCreationException {
    JibContainerBuilder containerBuilder =
        ContainerBuilders.create(
            "registry://registry-image-ref",
            Collections.emptySet(),
            mockCommonCliOptions,
            mockLogger);
    BuildContext buildContext =
        JibContainerBuilderTestHelper.toBuildContext(
            containerBuilder, Containerizer.to(RegistryImage.named("ignored")));
    ImageConfiguration imageConfiguration = buildContext.getBaseImageConfiguration();

    assertThat(imageConfiguration.getImage().toString()).isEqualTo("registry-image-ref");