Skip to content
Merged
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
@@ -1,14 +1,14 @@
package com.github.dockerjava.api.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

public class ExposedPorts implements Serializable {
private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -36,8 +36,9 @@ public static ExposedPorts fromPrimitive(Map<String, Object> object) {
@JsonValue
public Map<String, Object> toPrimitive() {
return Stream.of(exposedPorts).collect(Collectors.toMap(
ExposedPort::toString,
__ -> new Object()
ExposedPort::toString,
__ -> new Object(),
(a, b) -> a
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import org.junit.Test;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.aMapWithSize;
import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.notNullValue;

public class ExposedPortsTest {
Expand Down Expand Up @@ -46,4 +49,19 @@ public void usesFromJson() throws Exception {
new ExposedPort(3868, InternetProtocol.SCTP)
));
}

@Test
public void usesFromJsonWithDuplicate() throws Exception {
ExposedPorts ports = new ExposedPorts(
new ExposedPort(80, InternetProtocol.UDP),
new ExposedPort(80),
new ExposedPort(80)
);

assertThat(ports, notNullValue());
assertThat(ports.getExposedPorts(), arrayWithSize(3));

Map<String, Object> map = ports.toPrimitive();
assertThat(map, aMapWithSize(2));
}
}