X Tutup
Skip to content

Commit b1d77c5

Browse files
committed
Fix unrelable test.
1 parent e149bee commit b1d77c5

File tree

3 files changed

+87
-16
lines changed

3 files changed

+87
-16
lines changed

src/main/java/com/github/dockerjava/api/command/InspectContainerResponse.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,5 +462,68 @@ public String getMode() {
462462
public Boolean getRW() {
463463
return rw;
464464
}
465+
466+
/**
467+
* @see #destination
468+
*/
469+
public Mount withDestination(Volume destination) {
470+
this.destination = destination;
471+
return this;
472+
}
473+
474+
/**
475+
* @see #driver
476+
*/
477+
public Mount withDriver(String driver) {
478+
this.driver = driver;
479+
return this;
480+
}
481+
482+
/**
483+
* @see #mode
484+
*/
485+
public Mount withMode(String mode) {
486+
this.mode = mode;
487+
return this;
488+
}
489+
490+
/**
491+
* @see #name
492+
*/
493+
public Mount withName(String name) {
494+
this.name = name;
495+
return this;
496+
}
497+
498+
/**
499+
* @see #rw
500+
*/
501+
public Mount withRw(Boolean rw) {
502+
this.rw = rw;
503+
return this;
504+
}
505+
506+
/**
507+
* @see #source
508+
*/
509+
public Mount withSource(String source) {
510+
this.source = source;
511+
return this;
512+
}
513+
514+
@Override
515+
public String toString() {
516+
return ToStringBuilder.reflectionToString(this);
517+
}
518+
519+
@Override
520+
public boolean equals(Object o) {
521+
return EqualsBuilder.reflectionEquals(this, o);
522+
}
523+
524+
@Override
525+
public int hashCode() {
526+
return HashCodeBuilder.reflectionHashCode(this);
527+
}
465528
}
466529
}

src/test/java/com/github/dockerjava/core/command/StartContainerCmdImplTest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static org.hamcrest.Matchers.contains;
88
import static org.hamcrest.Matchers.containsInAnyOrder;
99
import static org.hamcrest.Matchers.equalTo;
10+
import static org.hamcrest.Matchers.hasSize;
1011
import static org.hamcrest.Matchers.is;
1112
import static org.hamcrest.Matchers.isEmptyString;
1213
import static org.hamcrest.Matchers.not;
@@ -15,6 +16,7 @@
1516

1617
import java.lang.reflect.Method;
1718
import java.util.Arrays;
19+
import java.util.List;
1820
import java.util.UUID;
1921

2022
import org.testng.ITestResult;
@@ -92,15 +94,16 @@ public void startContainerWithVolumes() throws DockerException {
9294

9395
assertThat(inspectContainerResponse, mountedVolumes(containsInAnyOrder(volume1, volume2)));
9496

95-
assertThat(inspectContainerResponse.getMounts().size(), equalTo(2));
97+
final List<InspectContainerResponse.Mount> mounts = inspectContainerResponse.getMounts();
9698

97-
assertThat(inspectContainerResponse.getMounts().get(0).getDestination(), equalTo(volume1));
98-
assertThat(inspectContainerResponse.getMounts().get(0).getMode(), equalTo("ro"));
99-
assertThat(inspectContainerResponse.getMounts().get(0).getRW(), equalTo(Boolean.FALSE));
99+
assertThat(mounts, hasSize(2));
100100

101-
assertThat(inspectContainerResponse.getMounts().get(1).getDestination(), equalTo(volume2));
102-
assertThat(inspectContainerResponse.getMounts().get(1).getMode(), equalTo("rw"));
103-
assertThat(inspectContainerResponse.getMounts().get(1).getRW(), equalTo(Boolean.TRUE));
101+
final InspectContainerResponse.Mount mount1 = new InspectContainerResponse.Mount()
102+
.withRw(false).withMode("ro").withDestination(volume1).withSource("/src/webapp1");
103+
final InspectContainerResponse.Mount mount2 = new InspectContainerResponse.Mount()
104+
.withRw(true).withMode("rw").withDestination(volume2).withSource("/src/webapp2");
105+
106+
assertThat(mounts, containsInAnyOrder(mount1, mount2));
104107
}
105108

106109
@Test

src/test/java/com/github/dockerjava/netty/exec/StartContainerCmdExecTest.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static org.hamcrest.Matchers.contains;
88
import static org.hamcrest.Matchers.containsInAnyOrder;
99
import static org.hamcrest.Matchers.equalTo;
10+
import static org.hamcrest.Matchers.hasSize;
1011
import static org.hamcrest.Matchers.is;
1112
import static org.hamcrest.Matchers.isEmptyString;
1213
import static org.hamcrest.Matchers.not;
@@ -15,6 +16,7 @@
1516

1617
import java.lang.reflect.Method;
1718
import java.util.Arrays;
19+
import java.util.List;
1820
import java.util.UUID;
1921

2022
import org.testng.ITestResult;
@@ -73,8 +75,10 @@ public void startContainerWithVolumes() throws DockerException {
7375

7476
Volume volume2 = new Volume("/opt/webapp2");
7577

76-
CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withVolumes(volume1, volume2)
77-
.withCmd("true").withBinds(new Bind("/src/webapp1", volume1, ro), new Bind("/src/webapp2", volume2))
78+
CreateContainerResponse container = dockerClient.createContainerCmd("busybox")
79+
.withVolumes(volume1, volume2)
80+
.withCmd("true")
81+
.withBinds(new Bind("/src/webapp1", volume1, ro), new Bind("/src/webapp2", volume2))
7882
.exec();
7983

8084
LOG.info("Created container {}", container.toString());
@@ -93,15 +97,16 @@ public void startContainerWithVolumes() throws DockerException {
9397

9498
assertThat(inspectContainerResponse, mountedVolumes(containsInAnyOrder(volume1, volume2)));
9599

96-
assertThat(inspectContainerResponse.getMounts().size(), equalTo(2));
100+
final List<InspectContainerResponse.Mount> mounts = inspectContainerResponse.getMounts();
97101

98-
assertThat(inspectContainerResponse.getMounts().get(0).getDestination(), equalTo(volume1));
99-
assertThat(inspectContainerResponse.getMounts().get(0).getMode(), equalTo("ro"));
100-
assertThat(inspectContainerResponse.getMounts().get(0).getRW(), equalTo(Boolean.FALSE));
102+
assertThat(mounts, hasSize(2));
101103

102-
assertThat(inspectContainerResponse.getMounts().get(1).getDestination(), equalTo(volume2));
103-
assertThat(inspectContainerResponse.getMounts().get(1).getMode(), equalTo("rw"));
104-
assertThat(inspectContainerResponse.getMounts().get(1).getRW(), equalTo(Boolean.TRUE));
104+
final InspectContainerResponse.Mount mount1 = new InspectContainerResponse.Mount()
105+
.withRw(false).withMode("ro").withDestination(volume1).withSource("/src/webapp1");
106+
final InspectContainerResponse.Mount mount2 = new InspectContainerResponse.Mount()
107+
.withRw(true).withMode("rw").withDestination(volume2).withSource("/src/webapp2");
108+
109+
assertThat(mounts, containsInAnyOrder(mount1, mount2));
105110
}
106111

107112
@Test

0 commit comments

Comments
 (0)
X Tutup