Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.dockerjava.api.exception.NotFoundException;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.io.InputStream;
import java.util.List;
Expand All @@ -22,10 +23,10 @@ interface TaggedImage {
/**
* Adds an image to the list of images to download.
* @param name image name (not null)
* @param tag tag
* @param tag tag (optional; when {@code null}, only the image name is used)
* @return this
*/
SaveImagesCmd withImage(@Nonnull String name, @Nonnull String tag);
SaveImagesCmd withImage(@Nonnull String name, @CheckForNull String tag);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.dockerjava.api.exception.NotFoundException;
import com.google.common.collect.ImmutableList;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.io.InputStream;
import java.util.List;
Expand All @@ -17,11 +18,14 @@ private static class TaggedImageImpl implements TaggedImage {

private TaggedImageImpl(String name, String tag) {
this.name = Objects.requireNonNull(name, "image name was not specified");
this.tag = Objects.requireNonNull(tag, "image tag was not specified");
this.tag = tag;
}

@Override
public String asString() {
if (tag == null) {
return name;
}
return name + ":" + tag;
}

Expand All @@ -38,7 +42,7 @@ public SaveImagesCmdImpl(final SaveImagesCmd.Exec exec) {
}

@Override
public SaveImagesCmd withImage(@Nonnull final String name, @Nonnull final String tag) {
public SaveImagesCmd withImage(@Nonnull final String name, @CheckForNull final String tag) {
taggedImages.add(new TaggedImageImpl(name, tag));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.github.dockerjava.core.command;

import com.github.dockerjava.api.command.SaveImagesCmd;
import org.junit.Test;

import java.io.InputStream;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class SaveImagesCmdImplTest {

private static final SaveImagesCmd.Exec NOOP_EXEC = new SaveImagesCmd.Exec() {
@Override
public InputStream exec(SaveImagesCmd command) {
return null;
}
};

@Test
public void withImageNullTagProducesNameOnly() {
SaveImagesCmd cmd = new SaveImagesCmdImpl(NOOP_EXEC).withImage("busybox", null);

List<SaveImagesCmd.TaggedImage> images = cmd.getImages();
assertEquals(1, images.size());
assertEquals("busybox", images.get(0).asString());
}

@Test
public void withImageTaggedFormRemainsNameColonTag() {
SaveImagesCmd cmd = new SaveImagesCmdImpl(NOOP_EXEC).withImage("busybox", "latest");

List<SaveImagesCmd.TaggedImage> images = cmd.getImages();
assertEquals(1, images.size());
assertEquals("busybox:latest", images.get(0).asString());
}
}